aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--list.c21
-rw-r--r--queue.c6
2 files changed, 18 insertions, 9 deletions
diff --git a/list.c b/list.c
index 24024da..5c36ea4 100644
--- a/list.c
+++ b/list.c
@@ -29,8 +29,9 @@ list_add(struct list_item *next, T data)
29 new_item->next = next; 29 new_item->next = next;
30 new_item->data = data; 30 new_item->data = data;
31 } 31 }
32 else 32 else {
33 ERROR("out of memory"); 33 ERROR("out of memory");
34 }
34 35
35 return new_item; 36 return new_item;
36} 37}
@@ -49,8 +50,9 @@ list_insert_next(struct list_item *list, T data)
49 new_item->next = list->next; 50 new_item->next = list->next;
50 list->next = new_item; 51 list->next = new_item;
51 } 52 }
52 else 53 else {
53 ERROR("out of memory"); 54 ERROR("out of memory");
55 }
54} 56}
55/* -->8-- */ 57/* -->8-- */
56 58
@@ -102,8 +104,9 @@ list_length(struct list_item *list)
102{ 104{
103 size_t len = 0; 105 size_t len = 0;
104 106
105 for ( ; list; list = list->next ) 107 for ( ; list; list = list->next ) {
106 ++len; 108 ++len;
109 }
107 110
108 return len; 111 return len;
109} 112}
@@ -121,8 +124,9 @@ list_copy(struct list_item *list)
121 (*p)->data = list->data; // copy elements 124 (*p)->data = list->data; // copy elements
122 p = &(*p)->next; 125 p = &(*p)->next;
123 } 126 }
124 else 127 else {
125 ERROR("out of memory"); 128 ERROR("out of memory");
129 }
126 } 130 }
127 *p = NULL; 131 *p = NULL;
128 return head; 132 return head;
@@ -162,10 +166,12 @@ list_merge(struct list_item *a, struct list_item *b)
162 struct list_item *head = &dummy, *c = head; 166 struct list_item *head = &dummy, *c = head;
163 167
164 while ( a != NULL && b != NULL ) 168 while ( a != NULL && b != NULL )
165 if ( a->data < b->data ) 169 if ( a->data < b->data ) {
166 c->next = a, c = a, a = a->next; 170 c->next = a, c = a, a = a->next;
167 else 171 }
172 else {
168 c->next = b, c = b, b = b->next; 173 c->next = b, c = b, b = b->next;
174 }
169 175
170 c->next = (a != NULL) ? a : b; 176 c->next = (a != NULL) ? a : b;
171 177
@@ -183,8 +189,9 @@ list_sort(struct list_item *c)
183 struct list_item *a = c, 189 struct list_item *a = c,
184 *b = c->next; 190 *b = c->next;
185 191
186 while ( b != NULL && b->next != NULL ) 192 while ( b != NULL && b->next != NULL ) {
187 c = c->next, b = b->next->next; 193 c = c->next, b = b->next->next;
194 }
188 195
189 b = c->next, c->next = NULL; 196 b = c->next, c->next = NULL;
190 197
diff --git a/queue.c b/queue.c
index dab5bfb..622609e 100644
--- a/queue.c
+++ b/queue.c
@@ -43,8 +43,9 @@ queue_put(struct queue *queue, T data)
43 else 43 else
44 tmp->next = queue->tail; 44 tmp->next = queue->tail;
45 } 45 }
46 else 46 else {
47 ERROR("out of memory"); 47 ERROR("out of memory");
48 }
48} 49}
49/* -->8-- */ 50/* -->8-- */
50 51
@@ -96,8 +97,9 @@ main()
96 97
97 queue_init(queue); 98 queue_init(queue);
98 99
99 for ( int i = 0; i != 10; ++i ) 100 for ( int i = 0; i != 10; ++i ) {
100 queue_put(queue, i); 101 queue_put(queue, i);
102 }
101 103
102 while ( !queue_empty(queue) ) { 104 while ( !queue_empty(queue) ) {
103 int i; 105 int i;