-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_linked_list_array.c
More file actions
49 lines (42 loc) · 885 Bytes
/
03_linked_list_array.c
File metadata and controls
49 lines (42 loc) · 885 Bytes
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
#include <stdio.h>
#define max 100
int key[max+2], next[max+2];
int h, z, x;
void list_initialize() {
h = 0;
z = 1;
next[h] = z;
next[z] = z;
x = 2;
}
void list_printer(int h) {
int r = h;
while(next[r] != z) {
printf("%c ", (char) key[next[r]]);
r = next[r];
}
printf("\n");
}
int insert_after(int v, int t) {
key[x] = v;
next[x] = next[t];
next[t] = x;
return ++x;
}
void delete_next(int t) {
next[t] = next[next[t]];
}
int main() {
list_initialize();
insert_after((int) 'S', h);
insert_after((int) 'L', h);
insert_after((int) 'A', h);
insert_after((int) 'I', next[next[h]]);
insert_after((int) 'T', next[next[next[next[h]]]]);
list_printer(h);
printf("\n");
for (int i=0; i!=x; ++i) {
printf("%c %d\n", (char) key[i], next[i]);
}
return 0;
}