1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| // DoubleList.c
#include <stdlib.h>
#include "DoubleList.h"
void initList(List* plist)
{
plist->head = (List*)malloc(sizeof(Node));
if (plist->head == NULL)
{
return;
}
plist->tail = (List*)malloc(sizeof(Node));
if (plist->tail == NULL)
{
free(plist->head);
return;
}
plist->head->prev = NULL;
plist->head->next = plist->tail;
plist->tail->next = NULL;
plist->tail->prev = plist->head;
plist->numberOfData = 0;
}
// 데이터 삽입(추가)
void insertList(List* plist, ListData data)
{
Node* newNode = (Node*)malloc(sizeof(Node));
if (newNode == NULL)
{
return;
}
newNode->data = data;
newNode->prev = plist->tail->prev;
plist->tail->prev->next = newNode;
newNode->next = plist->tail;
plist->tail->prev = newNode;
plist->numberOfData++;
}
// 데이터 조회(첫 번째)
int getFirstListData(List* plist, ListData* pdata)
{
if (plist->head->next == plist->tail)
{
return FALSE;
}
plist->current = plist->head->next;
*pdata = plist->current->data;
return TRUE;
}
// 데이터 조회(두 번째 이후)
int getNextListData(List* plist, ListData* pdata)
{
if (plist->current->next == plist->tail)
{
return FALSE;
}
plist->current = plist->current->next;
*pdata = plist->current->data;
return TRUE;
}
// 데이터 삭제
ListData removeListData(List* plist)
{
Node* rpos = plist->current;
ListData remv = rpos->data;
plist->current->prev->next = plist->current->next;
plist->current->next->prev = plist->current->prev;
plist->current = plist->current->prev;
free(rpos);
plist->numberOfData--;
return remv;
}
// 추가적인 함수
int getListLength(List* plist)
{
return plist->numberOfData;
}
|