1
/**//*
 2
    리스트(List) : 배열에 비해서 데이터의 입력과 삭제가 용이한 데이터 구조
 3
    (입력한 순서와 반대로 구성된 리스트 작성)
 4
*/
 5
#include <stdio.h>
 6
#include <malloc.h>
 7
 8
// 단일 링크드 리스트용 구조체
 9
struct Node
10
...{
11
    char Name[20];            //이름
12
    char Phone[20];            //전화번호
13
    struct Node *NextNode;    //다음 노드를 가리키는 포인터
14
};
15
16
struct Node *GetNode(void);
17
18
// 메인 함수
19
void main(void)
20
...{
21
    int i = 0;
22
    struct Node *head, *current;
23
24
    printf("데이터입력 : \n");
25
26
    head = NULL;//첫번째 데이터의 링크를 널로 초기화
27
    for(i = 0;i < 3;i++)
28
    ...{
29
        current = GetNode();
30
        scanf("%s %s", current->Name, current->Phone);
31
        current->NextNode = head;
32
        head = current;
33
    }
34
35
    printf("데이터출력 : \n");
36
37
    current = head;
38
    while(current != NULL)
39
    ...{
40
        printf("%s %s\n", current->Name, current->Phone);
41
        current = current->NextNode;
42
    }
43
}
44
45
// 메모리 할당 함수
46
struct Node *GetNode(void)
47
...{
48
    return (struct Node *)malloc(sizeof(struct Node));
49
}
50
51
/**//*
52
데이터입력 :
53
aaa 111
54
bbb 222
55
ccc 333
56
데이터출력 :
57
ccc 333
58
bbb 222
59
aaa 111
60
Press any key to continue
61
*/
62