Skip to content

Commit a83ac14

Browse files
committed
simplified condition in push_head method, and added comments
1 parent 3973c57 commit a83ac14

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sprint-2/implement_linked_list/linked_list.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def push_head(self, element):
88
if self.head:
99
node.next = self.head
1010
self.head.previous = self.head = node
11-
elif not self.head and not self.tail:
11+
else:
1212
self.head = node
1313
self.tail = node
1414
return node
@@ -26,15 +26,19 @@ def pop_tail(self):
2626
def remove(self, node):
2727
if self.head == node:
2828
if self.tail == node:
29+
# head == node, tail == node
2930
self.head = self.tail = None
3031
else:
32+
# head == node, tail != node
3133
self.head = node.next
3234
node.next.previous = node.previous = node.next = None
3335
else:
3436
if self.tail == node:
37+
# head != node, tail == node
3538
self.tail = node.previous
3639
node.previous.next = node.previous = node.next = None
3740
else:
41+
# head != node, tail != node
3842
node.previous.next = node.next
3943
node.next.previous = node.previous
4044
node.previous = node.next = None

0 commit comments

Comments
 (0)