annotate List.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 aef83aed7a07
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include<stdlib.h>
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
2 /* TODO: malloc. */
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
3 #include"List.h"
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
5 /*
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
6 * doubly-linked list.
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
7 * interfaces of these routines is based on glib.
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
8 *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
9 * Usage:
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
10 * create new list.
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
11 * list = NULL
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
12 * add new data
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
13 * list = _listAddFirst(list, data)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
14 * remove data from the list
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
15 * list = _listRemove(list, data)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
16 * get n-th data
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
17 * data = _listGetnthData(list, n)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
18 *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
19 *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
20 * NOTE:
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
21 * Although `struct List' is a doubly-linked List, the List
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
22 * is made as a Ring. An User's variable is treated as a
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
23 * head of the list. And head->prev is last. And then if
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
24 * list have only one data, both next and prev field of
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
25 * head will point to oneself.
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
26 * If the variable is NULL, it means no data.
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
27 */
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 List *
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 _listAddFirst(List* top, void *data)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 List *newlist;
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
33 List *last;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
34 newlist = malloc(sizeof(struct _List));
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
35 newlist->data = data;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
36
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 if (!top) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 newlist->next = newlist;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 newlist->prev = newlist;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 return newlist;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
42 last = top->prev;
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 newlist->next = top;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 newlist->prev = last;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 top->prev = newlist;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 last->next = newlist;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 return newlist;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 List *
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 _listRemove(List *top, void *data)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 List *t;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 if (top->data==data) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 if (top->next==top) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 free(top);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 return NULL;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 List *newtop = top->next;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 top->next->prev = top->prev;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 top->prev->next = top->next;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 free(top);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 return newtop;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 for (t=top->next; t!=top; t=t->next) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 if (t->data==data) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 t->next->prev = t->prev;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 t->prev->next = t->next;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 free(t);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 return top;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 return top;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 void *
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 _listGetnthData(List *top, int n)
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 List *t;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 for (t=top; n>0; n--) {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 t = t->next;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 if (t==top) return NULL;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 return t->data;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 }
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
89 void *
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
90 _listGetLastData(List *top)
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
91 {
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
92 if (!top) return NULL;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
93 return top->prev->data;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
94 }
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
95
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
96 List *
1
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
97 _listMoveLasttoFirst(List *top)
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
98 {
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
99 if (!top) return NULL;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
100 return top->prev;
aef83aed7a07 scheduler test success.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
101 }
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 void
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
104 _listApply(List *top, ApplyFn fn, void *arg)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
105 {
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 List *t = top;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 do {
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 fn(t->data, arg);
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 t = t->next;
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 } while ( t!=top );
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 }
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
113 /*
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
114 * Iterator's functions.
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
115 *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
116 * iter = _listIterator(list);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
117 * while ( (data=_listIterNext(iter)!=NULL ) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
118 * exe(data);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
119 * if (data...) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
120 * list = _listIterRemove(iter);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
121 * }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
122 * }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
123 */
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
124 ListIter *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
125 _listIterator(List *top)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
126 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
127 ListIter *iter;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
128 iter = malloc(sizeof(struct _ListIter));
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
129 iter->head = top;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
130 iter->next = top;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
131 return iter;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
132 }
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
134 void *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
135 _listIterNext(ListIter *iter)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
136 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
137 void *rtn;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
138 if (!iter->next) return NULL;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
139
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
140 rtn = iter->next->data;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
141 iter->next = iter->next->next;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
142 if (iter->next==iter->head) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
143 iter->next = NULL;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
144 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
145 return rtn;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
146 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
147
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
148 void
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
149 _listIterEnd(ListIter *iter)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
150 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
151 free(iter);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
152 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
153
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
154 List *
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
155 _listIterRemoveCurrent(ListIter *iter)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
156 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
157 List *cur, *p, *n;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
158 if (!iter->head) return NULL;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
159 else if (!iter->next) cur = iter->head->prev;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
160 else cur = iter->next->prev;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
161
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
162 if (cur==iter->head) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
163 if (cur->next==iter->head) {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
164 free(iter->head);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
165 return NULL;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
166 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
167 iter->head = iter->head->next;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
168 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
169 cur->prev->next = cur->next;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
170 cur->next->prev = cur->prev;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
171
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
172 free(cur);
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
173 return iter->head;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
174 }
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
177 /*
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
178 * for DEBUG
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
179 */
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
181 int
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
182 _listRingCheck(List *head)
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
183 {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
184 List *cur = head;
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
186 if (cur->prev->next!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
187 if (cur->next->prev!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
188 do {
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
189 if (cur->prev->next!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
190 if (cur->next->prev!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
191 cur = cur->prev;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
192 } while (cur!=head);
0
5b089096921f first commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
2
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
194 if (cur->prev->next!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
195 if (cur->next->prev!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
196 cur = cur->next;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
197 if (cur->prev->next!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
198 if (cur->next->prev!=cur) return 0;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
199
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
200 return 1;
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
201 }
803d6bf22e6d second commit.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
202