다음 C 코드는 단순 연결 리스트를 이용하여 스택의 pop() 함수를 구현한 것이다. (가), (나)에 들어갈 내용을 바르게 연결한 것은?
struct stack {
int data;
struct stack* link;
};
struct stack* top = NULL;
int pop(){
struct stack* temp = top;
int item;
if (!temp){
printf("Stack is empty.\n");
exit(1);
}
item = temp->data;
(가) ;
free(temp);
(나) ;
} (가) (나)
- ①temp = temp->link return item
- ②temp = temp->link return top->data
- ③top = temp->link return item
- ④top = temp->link return top->data
선지를 골라 바로 채점해 보세요.
정답 ③
출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)