diff --git "a/03 \353\263\264\353\204\210\354\212\244 - \353\260\260\354\232\264 \352\262\203 \354\235\221\354\232\251\355\225\230\352\270\260/03-linked-list.py" "b/03 \353\263\264\353\204\210\354\212\244 - \353\260\260\354\232\264 \352\262\203 \354\235\221\354\232\251\355\225\230\352\270\260/03-linked-list.py" index 4d928f7..1fefd76 100644 --- "a/03 \353\263\264\353\204\210\354\212\244 - \353\260\260\354\232\264 \352\262\203 \354\235\221\354\232\251\355\225\230\352\270\260/03-linked-list.py" +++ "b/03 \353\263\264\353\204\210\354\212\244 - \353\260\260\354\232\264 \352\262\203 \354\235\221\354\232\251\355\225\230\352\270\260/03-linked-list.py" @@ -47,18 +47,20 @@ def push(self, item: T) -> None: cur_node = cur_node.pointer cur_node.pointer = new_node - def pop(self) -> T: + def pop(self) -> Optional[T]: if self.head is None: - raise ValueError("stack is empty") - cur_node = self.head + raise ValueError("Stack is empty") + cur_node: Node[T] = self.head if cur_node.pointer is None: self.head = None return cur_node.item - while cur_node.pointer.pointer is not None: - cur_node = cur_node.pointer - result = cur_node.pointer - cur_node.pointer = None - return result.item + while cur_node.pointer is not None: + if cur_node.pointer.pointer is not None: + cur_node = cur_node.pointer + continue + result = cur_node.pointer + cur_node.pointer = None + return result.item if result is not None else None class Queue(Generic[T], LinkedList[T]):