/
listdriver.c
69 lines (55 loc) · 1.5 KB
/
listdriver.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
#include <stdlib.h>
#include <stddef.h>
#include "List.h"
int intGreater(void * pLeft, void * pRight) {
int * pLeftInt = (int *) pLeft;
int * pRightInt = (int *) pRight;
if (!pLeftInt || !pRightInt) return -2; //Invalid
else if (*pLeftInt > *pRightInt) return 1; //Greater
else if (*pLeftInt == *pRightInt) return 0; //Equal
else return -1; //Less
}
int main() {
int data1,data2,data3,data4,data5;
int nonData = 6;
int * pFind = NULL;
List test = NULL;
initList(&test);
data1 = 10;data2 = 20;data3 = 30;data4 = 40;data5 = 50;
addToList(test, (void*)&data1);
addToList(test, (void*)&data2);
addToList(test, (void*)&data3);
addToList(test, (void*)&data4);
addToList(test, (void*)&data5);
displayList(test);
printf("%s","Searching for 30");
pFind = (int*)findInList(test, (void*)&data3, intGreater);
if (pFind)
{
printf("%s%d","\nFound data value: ", *pFind);
}
else {
printf("%s","\nData not found");
}
printf("%s","\nSearching for 99 (shouldn't be in list)");
pFind = (int*)findInList(test, (void*)&nonData, intGreater);
if (pFind)
{
printf("%s%d","\nFound data value: ", *pFind);
}
else {
printf("%s","\nData not found");
}
printf("%s","\nremoving one item then displaying\n");
removeFirst(test);
displayList(test);
printf("%s","removing all items then displaying\n");
deleteList(test);
displayList(test);
printf("%s","Attempting to remove from an empty list\n");
removeFirst(test);
displayList(test);
cleanupList(&test);
printf("%s","All tests complete\n");
return 0;
}