aboutsummaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-10-25 13:50:34 +0100
committerThomas Schmucker <ts@its1.de>2020-10-25 13:50:34 +0100
commitb0749a900f214f11d89a34bd605b66f1b0ed1d19 (patch)
tree51bea40782975c6d79acc6838d3d552518b442fd /list.c
parentafcdab8a2d1c76d7631693531dc07ab5578bf24c (diff)
downloaddata-structures-b0749a900f214f11d89a34bd605b66f1b0ed1d19.tar.gz
data-structures-b0749a900f214f11d89a34bd605b66f1b0ed1d19.tar.bz2
data-structures-b0749a900f214f11d89a34bd605b66f1b0ed1d19.zip
fix: neue Klammerung
Diffstat (limited to 'list.c')
-rw-r--r--list.c21
1 files changed, 14 insertions, 7 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