다음은 단순 연결 리스트를 이용하여 스택 자료구조를 구현한 파이썬 코드이다. (가), (나)에 들어갈 내용을 바르게 연결한 것은?
class Node: def __init__(self, data, next): self.data = data self.next = next class MyStack: def __init__(self): self.top = None def push(self, data): (가) self.top = n def pop(self): if self.top != None: n = self.top (나) return n.data
(가) (나)
- ①n = Node(data, None) self.top = n.next.next
- ②n = Node(data, None) self.top = self.top.next
- ③n = Node(data, self.top) self.top = n.next.next
- ④n = Node(data, self.top) self.top = self.top.next
선지를 골라 바로 채점해 보세요.
정답 ④
출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)