74. 연결 리스트의 앞쪽 삽입과 노드 삭제
다음 C 프로그램의 실행 결과를 쓰시오.
1#include <stdio.h>2#include <stdlib.h>34struct Node {5int val;6struct Node *next;7};89void push(struct Node **head, int v) {10struct Node *n = (struct Node *)malloc(sizeof(struct Node));11n->val = v;12n->next = *head;13*head = n;14}1516int show(struct Node *p) {17int sum = 0;18while (p != NULL) {19printf("%d", p->val);20sum += p->val;21p = p->next;22printf(p != NULL ? "->" : "\n");23}24return sum;25}2627int main() {28int data[4] = {4, 7, 2, 9};29struct Node *head = NULL;30for (int i = 0; i < 4; i++) {31push(&head, data[i]);32}33int s1 = show(head);34struct Node *del = head->next;35head->next = del->next;36free(del);37int s2 = show(head);38printf("%d %d\n", s1, s2);39while (head != NULL) {40struct Node *t = head;41head = head->next;42free(t);43}44return 0;45}