[7급 국가직 자료구조론 2024년 13번]

다음은 단순 연결 리스트를 이용하여 스택 자료구조를 구현한 파이썬 코드이다. (가), (나)에 들어갈 내용을 바르게 연결한 것은?
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
(가) (나)
자료구조론
  1. ①n = Node(data, None) self.top = n.next.next
  2. ②n = Node(data, None) self.top = self.top.next
  3. ③n = Node(data, self.top) self.top = n.next.next
  4. ④n = Node(data, self.top) self.top = self.top.next

선지를 골라 바로 채점해 보세요.

정답 ④

출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)

신고가 접수됐습니다. 감사합니다.

오류 신고