/
main.c
70 lines (52 loc) · 1.35 KB
/
main.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
/*
* sorted-list.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sorted-list.h"
int compareInts(void *p1, void *p2)
{
int i1 = *(int*)p1;
int i2 = *(int*)p2;
return i1 - i2;
}
int compareDoubles(void *p1, void *p2)
{
double d1 = *(double*)p1;
double d2 = *(double*)p2;
return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0);
}
int compareStrings(void *p1, void *p2)
{
char *s1 = p1;
char *s2 = p2;
return strcmp(s1, s2);
}
int main(int argc, char** argv){
//***************** STRING TEST ***********************
int i;
const char* stringList[] = {"Hey", "Boy", "Zeus", "world", " ", "blah", " zzz", "aaa"};
char* stringPtr = (char*) malloc(sizeof(stringList));
SortedListPtr stringsl = SLCreate(compareStrings, NULL);
/*
for(i=0; i<(sizeof(stringList)/sizeof(stringList[0])); i++){
stringPtr = (char*) stringList[i];
SLInsert(stringsl, stringPtr);
}
*/
SortedListIteratorPtr stringiterator2 = SLCreateIterator(stringsl);
SLNextItem(stringiterator2);
SLInsert(stringsl, "f");
SLInsert(stringsl, "d");
SLInsert(stringsl, "b");
//SLRemove(stringsl, "Apple");
SortedListIteratorPtr stringiterator = SLCreateIterator(stringsl);
while((stringPtr = (char*) SLNextItem(stringiterator)) != NULL){
printf("%s\n", stringPtr);
}
//cleans mess
free(stringPtr);
SLDestroy(stringsl);
SLDestroyIterator(stringiterator);
}