-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
executable file
·99 lines (75 loc) · 2.07 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
#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 numVotes %d", item.participantName, item.numVotes);
pos = next(pos, list);
}
}
printf(")\n");
}
int main() {
tList list;
tPosL pos;
tItemL item1, item2;
/* create */
createEmptyList(&list);
print_list(list);
/* insert */
strcpy(item1.participantName, "country3");
item1.numVotes = 0;
item1.EUParticipant = true;
insertItem(item1, LNULL, &list);
print_list(list);
strcpy(item1.participantName, "country1");
insertItem(item1, first(list), &list);
print_list(list);
strcpy(item1.participantName, "country5");
insertItem(item1, LNULL, &list);
print_list(list);
strcpy(item1.participantName, "country2");
insertItem(item1, next(first(list),list), &list);
print_list(list);
strcpy(item1.participantName, "country4");
insertItem(item1, last(list), &list);
print_list(list);
/* find */
pos = findItem("country33", list);
if (pos == LNULL) {
printf("country33 Not found\n");
}
pos = findItem("country3", list);
item2 = getItem(pos, list);
printf("%s\n", item2.participantName);
/* update */
item2 = getItem(pos, list);
item2.numVotes = 2;
updateItem(item2,pos,&list);
printf("%s\n", item2.participantName);
print_list(list);
/* remove */
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);
}