-
Notifications
You must be signed in to change notification settings - Fork 0
/
스텍_연결리스트.c
79 lines (61 loc) · 1.25 KB
/
스텍_연결리스트.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct DListNode
{
char data;
struct DListNode* prev, * next;
}DListNode;
typedef struct
{
DListNode* H;
}DlistType;
void init(DlistType* DL)
{
DL->H = NULL;
}
void insertFirst(DlistType* DL, char e)
{
DListNode* node = (DListNode*)malloc(sizeof(DListNode));
DListNode* p = DL->H;
node->data = e;
node->prev = NULL;
node->next = p;
DL->H = node;
if(p != NULL)
p->prev = node;
}
void insert(DlistType* DL, int pos, char e)
{
DListNode* node = (DListNode*)malloc(sizeof(DListNode));
DListNode *p = DL->H;
if(pos == 1)
insertFirst(DL, e);
else
{
for(int i = 1; i < pos; i++)
p = p->next;
node->data = e;
node->prev = p->prev;
node->next = p;
node->prev->next = node;
p->prev = node;
}
}
void print(DlistType* DL)
{
for(DListNode* p = DL->H; p != NULL; p = p->next)
printf("%c <=> ", p->data);
printf("\b\b\b\b \n");
}
int main(void)
{
DlistType DL;
init(&DL);
insertFirst(&DL, 'A'); print(&DL);
insertFirst(&DL, 'B'); print(&DL);
insertFirst(&DL, 'C'); print(&DL);
getchar();
insert(&DL, 2, )
return 0;
}