Skip to content

Stack 샘플 예제 TypeCheck 에러 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: inflearn
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions 03 보너스 - 배운 것 응용하기/03-linked-list.py
Original file line number Diff line number Diff line change
@@ -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]):