C출력 결과보통 · 20점#연결 리스트#구조체#포인터

262. 구조체 배열로 만든 연결 리스트의 노드 삭제

다음 C 프로그램의 실행 결과를 쓰시오.

1#include <stdio.h>
2
3struct Node {
4 int v;
5 struct Node *next;
6};
7
8int main() {
9 struct Node n[4] = {{5, NULL}, {8, NULL}, {3, NULL}, {6, NULL}};
10 n[0].next = &n[2];
11 n[2].next = &n[1];
12 n[1].next = &n[3];
13 struct Node *prev = &n[0];
14 struct Node *cur = prev->next;
15 while (cur->v != 8) {
16 prev = cur;
17 cur = cur->next;
18 }
19 prev->next = cur->next;
20 int sum = 0;
21 for (struct Node *p = &n[0]; p != NULL; p = p->next) {
22 printf("%d ", p->v);
23 sum += p->v;
24 }
25 printf("\n%d %d\n", sum, cur->next->v);
26 return 0;
27}

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.