2
|
1 #include<stdio.h>
|
|
2 #include<stdlib.h>
|
|
3 #include<string.h>
|
|
4 #include<assert.h>
|
|
5
|
|
6 #include"List.h"
|
|
7
|
|
8 void printList(List *list);
|
|
9 int test0();
|
|
10 int _listRingCheck(List *head);
|
|
11
|
|
12 int
|
|
13 main(int argc, char **argv)
|
|
14 {
|
|
15 test0();
|
|
16 return 0;
|
|
17 }
|
|
18
|
|
19 int
|
|
20 test0()
|
|
21 {
|
|
22 char *data = "abcdefghijklmnopqrstuvwxyz";
|
|
23 List *list=NULL;
|
|
24 ListIter *iter=NULL;
|
|
25 int i;
|
|
26 char input;
|
|
27
|
|
28 for (i=0; data[i]!='\0'; i++) {
|
|
29 list = _listAddFirst(list, (void*)data[i]);
|
|
30 }
|
|
31 printList(list);
|
|
32 assert(_listRingCheck(list));
|
|
33
|
|
34
|
|
35 iter = _listIterator(list);
|
|
36 while ((data=_listIterNext(iter))!=NULL) {
|
|
37 int c=(int)data;
|
|
38 printf("%c ", c);
|
|
39 }
|
|
40 _listIterEnd(iter);
|
|
41 printf("\n");
|
|
42
|
|
43
|
|
44 i=0;
|
|
45 iter = _listIterator(list);
|
|
46 while ((data=_listIterNext(iter))!=NULL) {
|
|
47 if (i%2==1) {
|
|
48 list = _listIterRemoveCurrent(iter);
|
|
49 }
|
|
50 i++;
|
|
51 }
|
|
52 _listIterEnd(iter);
|
|
53 printf("\n");
|
|
54 assert(_listRingCheck(list));
|
|
55
|
|
56 iter = _listIterator(list);
|
|
57 while ((data=_listIterNext(iter))!=NULL) {
|
|
58 int c=(int)data;
|
|
59 printf("%c ", c);
|
|
60 }
|
|
61 _listIterEnd(iter);
|
|
62 printf("\n");
|
|
63
|
|
64 return 0;
|
|
65 }
|
|
66
|
|
67
|
|
68 int printOne(void *data,void *arg)
|
|
69 {
|
|
70 char c = (char)data;
|
|
71 printf("%c ", c);
|
|
72 return 1;
|
|
73 }
|
|
74 void
|
|
75 printList(List *list)
|
|
76 {
|
|
77 _listApply(list, printOne, NULL);
|
|
78 printf("\n");
|
|
79 }
|
|
80
|
|
81
|
|
82
|
|
83
|
|
84
|