프로그래밍 언어 활용난도 중상
12번 · 주관식 · 5점
다음 C 프로그램의 실행 결과를 쓰시오.
#include <stdio.h>
struct Node {
int value;
struct Node *next;
};
void swap_pairs(struct Node *node) {
while (node != NULL && node->next != NULL) {
int temp = node->value;
node->value = node->next->value;
node->next->value = temp;
node = node->next->next;
}
}
int main(void) {
struct Node n1 = {1, NULL};
struct Node n2 = {2, NULL};
struct Node n3 = {3, NULL};
n1.next = &n3;
n3.next = &n2;
swap_pairs(&n1);
for (struct Node *p = &n1; p != NULL; p = p->next) {
printf("%d", p->value);
}
return 0;
}