We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cf9785c commit abe3707Copy full SHA for abe3707
linked_stack/linked_stack.py
@@ -34,7 +34,12 @@ def push(self, new_element: Element) -> None:
34
35
def pop(self) -> Element:
36
old_head = self.head
37
- self.head = old_head.next
+ 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
43
return old_head
44
45
@@ -48,3 +53,6 @@ def pop(self) -> Element:
48
53
linked_stack.push(third_el)
49
54
50
55
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