다음 코드는 C 언어를 이용하여 주어진 연결 리스트 구조의 데이터에 대한 삽입 정렬 함수를 구현한 것이다. ㉠ ~ ㉤에 들어갈 코드를 바르게 연결한 것은?
typedef struct _node {
int data;
struct _node *next;
}node;
void Insert(node **headRef, node *newNode) {
if (*headRef == NULL ||
(*headRef)->data >= newNode->data) {
newNode->next = *headRef;
*headRef = newNode;
}
else {
node *current = *headRef;
while (current->next != NULL &&
current->next->data < newNode->data){
㉠
}
㉡
㉢
}
}
void Sort(node **headRef) {
node *result = NULL, *current = *headRef;
node *next;
while (current!=NULL) {
㉣
Insert(&result, current);
㉤
}
*headRef = result;
} |
A : current->next = current;
B : current = current->next;
C : current->next = newNode;
D : next = current->next;
E : current->next = next;
F : current = next;
G : newNode->next = current->next; |
㉠ ㉡ ㉢ ㉣ ㉤
- ①A D E F G
- ②B G C D F
- ③C E B A D
- ④E G B F A
선지를 골라 바로 채점해 보세요.
정답 ②
출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)