Skip to content

Commit abe3707

Browse files
Fix linked stack delete
1 parent cf9785c commit abe3707

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

linked_stack/linked_stack.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ def push(self, new_element: Element) -> None:
3434

3535
def pop(self) -> Element:
3636
old_head = self.head
37-
self.head = old_head.next
37+
if self.head is None:
38+
return None
39+
if self.head.next is None:
40+
self.head = None
41+
else:
42+
self.head = old_head.next
3843
return old_head
3944

4045

@@ -48,3 +53,6 @@ def pop(self) -> Element:
4853
linked_stack.push(third_el)
4954

5055
assert linked_stack.pop() is third_el
56+
assert linked_stack.pop() is second_el
57+
assert linked_stack.pop() is first_el
58+
assert linked_stack.pop() is None

0 commit comments

Comments
 (0)