Skip to content

Commit cd10c94

Browse files
ManuMBhatcclauss
authored andcommitted
Issue #1397 (#1403)
1 parent ab65a39 commit cd10c94

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

data_structures/linked_list/singly_linked_list.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,56 @@ def __init__(self, data):
66

77
class Linked_List:
88
def __init__(self):
9-
self.Head = None # Initialize Head to None
9+
self.head = None # Initialize head to None
1010

1111
def insert_tail(self, data):
12-
if self.Head is None:
12+
if self.head is None:
1313
self.insert_head(data) # If this is first node, call insert_head
1414
else:
15-
temp = self.Head
15+
temp = self.head
1616
while temp.next != None: # traverse to last node
1717
temp = temp.next
1818
temp.next = Node(data) # create node & link to tail
1919

2020
def insert_head(self, data):
2121
newNod = Node(data) # create a new node
22-
if self.Head != None:
23-
newNod.next = self.Head # link newNode to head
24-
self.Head = newNod # make NewNode as Head
22+
if self.head != None:
23+
newNod.next = self.head # link newNode to head
24+
self.head = newNod # make NewNode as head
2525

2626
def printList(self): # print every node data
27-
tamp = self.Head
28-
while tamp is not None:
29-
print(tamp.data)
30-
tamp = tamp.next
27+
temp = self.head
28+
while temp is not None:
29+
print(temp.data)
30+
temp = temp.next
3131

3232
def delete_head(self): # delete from head
33-
temp = self.Head
34-
if self.Head != None:
35-
self.Head = self.Head.next
33+
temp = self.head
34+
if self.head != None:
35+
self.head = self.head.next
3636
temp.next = None
3737
return temp
3838

3939
def delete_tail(self): # delete from tail
40-
tamp = self.Head
41-
if self.Head != None:
42-
if self.Head.next is None: # if Head is the only Node in the Linked List
43-
self.Head = None
40+
temp = self.head
41+
if self.head != None:
42+
if self.head.next is None: # if head is the only Node in the Linked List
43+
self.head = None
4444
else:
45-
while tamp.next.next is not None: # find the 2nd last element
46-
tamp = tamp.next
47-
tamp.next, tamp = (
45+
while temp.next.next is not None: # find the 2nd last element
46+
temp = temp.next
47+
temp.next, temp = (
4848
None,
49-
tamp.next,
50-
) # (2nd last element).next = None and tamp = last element
51-
return tamp
49+
temp.next,
50+
) # (2nd last element).next = None and temp = last element
51+
return temp
5252

5353
def isEmpty(self):
54-
return self.Head is None # Return if Head is none
54+
return self.head is None # Return if head is none
5555

5656
def reverse(self):
5757
prev = None
58-
current = self.Head
58+
current = self.head
5959

6060
while current:
6161
# Store the current node's next node.
@@ -67,15 +67,15 @@ def reverse(self):
6767
# Make the current node the next node (to progress iteration)
6868
current = next_node
6969
# Return prev in order to put the head at the end
70-
self.Head = prev
70+
self.head = prev
7171

7272

7373
def main():
7474
A = Linked_List()
75-
print("Inserting 1st at Head")
75+
print("Inserting 1st at head")
7676
a1 = input()
7777
A.insert_head(a1)
78-
print("Inserting 2nd at Head")
78+
print("Inserting 2nd at head")
7979
a2 = input()
8080
A.insert_head(a2)
8181
print("\nPrint List : ")
@@ -88,7 +88,7 @@ def main():
8888
A.insert_tail(a4)
8989
print("\nPrint List : ")
9090
A.printList()
91-
print("\nDelete Head")
91+
print("\nDelete head")
9292
A.delete_head()
9393
print("Delete Tail")
9494
A.delete_tail()

0 commit comments

Comments
 (0)