class Node:
def __init__(self, item, next):
self.item = item
self.next = next
class Stack:
def __init__(self):
self.cur = None
# 요소 추가하면서 포인터인 cur은 추가한 요소를 바라보게하고, 추가하기 이전 값은 next로 바라보게한다.
def push(self, item):
self.cur = Node(item, self.cur)
# 마지막 아이템을 꺼내고, 그이전 값으로 포인터인 cur을 변경
def pop(self):
item = self.cur.item
self.cur = self.cur.next
return item
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
stack.push(4)
print(stack.pop())
# 4