1
/**//*
 2
    데이터구조 : 리스트(List) : FIFO형 리스트
 3
*/
 4
#include <stdio.h>
 5
#include <malloc.h>
 6
 7
// 단일 링크드 리스트용 구조체
 8
struct Node
 9
...{
10
    char Name[20];            //이름
11
    char Phone[20];            //전화번호
12
    struct Node *NextNode;    //재귀 : 다음 노드를 가리키는 포인터
13
};
14
15
struct Node *GetNode(void);
16
17
// 메인 함수
18
void main(void)
19
...{
20
    int i = 0;
21
    struct Node *head, *current, *old;
22
23
    printf("데이터 입력 : \n");
24
    head = GetNode();
25
    scanf("%s %s", head->Name, head->Phone); //미리 데이터 입력
26
27
    old = head;//old포인터 : 이전 노드를 가리키는 포인터
28
    for(i = 0;i < 2;i++)
29
    ...{
30
        current = GetNode();
31
        scanf("%s %s", current->Name, current->Phone);
32
        old->NextNode = current;
33
        old = current;
34
    }
35
    old->NextNode = NULL;
36
37
    printf("데이터 출력 : \n");
38
    current = head;
39
    while(current != NULL)
40
    ...{
41
        printf("%s %s \n", current->Name, current->Phone);
42
        current = current->NextNode;
43
    }
44
}
45
46
// 메모리 할당 함수
47
struct Node *GetNode(void)
48
...{
49
    return (struct Node *)malloc(sizeof(struct Node));
50
}