annotate test/list/testiter.c @ 2:803d6bf22e6d default tip

second commit. it's far to complete..
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Dec 2009 16:19:56 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include<stdio.h>
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include<stdlib.h>
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include<string.h>
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include<assert.h>
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include"List.h"
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 void printList(List *list);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 int test0();
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 int _listRingCheck(List *head);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 int
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 main(int argc, char **argv)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 test0();
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 int
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 test0()
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 char *data = "abcdefghijklmnopqrstuvwxyz";
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 List *list=NULL;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 ListIter *iter=NULL;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 int i;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 char input;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 for (i=0; data[i]!='\0'; i++) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 list = _listAddFirst(list, (void*)data[i]);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 printList(list);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 assert(_listRingCheck(list));
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 iter = _listIterator(list);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 while ((data=_listIterNext(iter))!=NULL) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 int c=(int)data;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 printf("%c ", c);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 _listIterEnd(iter);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 printf("\n");
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 i=0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 iter = _listIterator(list);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 while ((data=_listIterNext(iter))!=NULL) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 if (i%2==1) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 list = _listIterRemoveCurrent(iter);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 i++;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 _listIterEnd(iter);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 printf("\n");
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 assert(_listRingCheck(list));
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 iter = _listIterator(list);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 while ((data=_listIterNext(iter))!=NULL) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 int c=(int)data;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 printf("%c ", c);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 _listIterEnd(iter);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 printf("\n");
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 int printOne(void *data,void *arg)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 char c = (char)data;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 printf("%c ", c);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 return 1;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 void
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 printList(List *list)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 _listApply(list, printOne, NULL);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 printf("\n");
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84