-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
106 lines (75 loc) · 1.99 KB
/
test.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <string.h>
#ifdef DYNAMIC_LIST
#include "dynamic_list.h"
#endif
#ifdef STATIC_LIST
#include "static_list.h"
#endif
void print_list(tList list) {
tPosL pos;
tItemL item;
printf("(");
if (!isEmptyList(list)) {
pos = first(list);
while (pos != LNULL) {
item = getItem(pos, list);
printf(" %s numPlays %d", item.userName, item.numPlay);
pos = next(pos, list);
}
}
printf(")\n");
}
int main() {
tList list;
tPosL pos;
tItemL item1, item2;
/* create */
createEmptyList(&list);
print_list(list);
/* insert */
strcpy(item1.userName, "user3");
item1.numPlay = 0;
item1.userCategory = basic;
insertItem(item1, LNULL, &list);
print_list(list);
strcpy(item1.userName, "user1");
insertItem(item1, first(list), &list);
print_list(list);
strcpy(item1.userName, "user5");
insertItem(item1, LNULL, &list);
print_list(list);
strcpy(item1.userName, "user2");
insertItem(item1, next(first(list), list), &list);
print_list(list);
strcpy(item1.userName, "user4");
insertItem(item1, last(list), &list);
print_list(list);
/* find */
pos = findItem("user33", list);
if (pos == LNULL) {
printf("user33 Not found\n");
}
pos = findItem("user3", list);
item2 = getItem(pos, list);
printf("%s\n", item2.userName);
//update
item2 = getItem(pos, list);
item2.numPlay = 2;
updateItem(item2,pos,&list);
printf("%s\n", item2.userName);
print_list(list);
//delete
deleteAtPosition(next(first(list),list), &list);
print_list(list);
deleteAtPosition(previous(last(list),list), &list);
print_list(list);
deleteAtPosition(first(list),&list);
print_list(list);
deleteAtPosition(last(list),&list);
print_list(list);
deleteAtPosition(first(list),&list);
print_list(list);
insertItem(item1, LNULL, &list);
print_list(list);
}