์๊ณ ๋ฆฌ์ฆ
2023. 5. 24.
์๋ฃ๊ตฌ์กฐ - Stack, Queue | ๋ฐฑ์ค 10828 , 10773 Python
1. Stack์ ๋
ธ๋ ๊ธฐ๋ณธ ๋จ์ class Node: def __init__(self, item, next): self.item = item self.next = next 2. Stack์ ๊ตฌ์ฑ class Stack: def __init__(self): self.top = None #push, pop, is empty def is_empty(self): return self.top is None def push(self, val): self.top = Node(val, self.top) # val == item, self.top == next(๋ค์ ๊ฐ๋ฆฌํค๋ ๊ฒ)) def pop(self): if not self.top: return None node = self.top #๊ฐ์ฅ ์ต๊ทผ ์ถ๊ฐ๋ top nod..