From b0749a900f214f11d89a34bd605b66f1b0ed1d19 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 25 Oct 2020 13:50:34 +0100 Subject: fix: neue Klammerung --- list.c | 21 ++++++++++++++------- queue.c | 6 ++++-- 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) new_item->next = next; new_item->data = data; } - else + else { ERROR("out of memory"); + } return new_item; } @@ -49,8 +50,9 @@ list_insert_next(struct list_item *list, T data) new_item->next = list->next; list->next = new_item; } - else + else { ERROR("out of memory"); + } } /* -->8-- */ @@ -102,8 +104,9 @@ list_length(struct list_item *list) { size_t len = 0; - for ( ; list; list = list->next ) + for ( ; list; list = list->next ) { ++len; + } return len; } @@ -121,8 +124,9 @@ list_copy(struct list_item *list) (*p)->data = list->data; // copy elements p = &(*p)->next; } - else + else { ERROR("out of memory"); + } } *p = NULL; return head; @@ -162,10 +166,12 @@ list_merge(struct list_item *a, struct list_item *b) struct list_item *head = &dummy, *c = head; while ( a != NULL && b != NULL ) - if ( a->data < b->data ) + if ( a->data < b->data ) { c->next = a, c = a, a = a->next; - else + } + else { c->next = b, c = b, b = b->next; + } c->next = (a != NULL) ? a : b; @@ -183,8 +189,9 @@ list_sort(struct list_item *c) struct list_item *a = c, *b = c->next; - while ( b != NULL && b->next != NULL ) + while ( b != NULL && b->next != NULL ) { c = c->next, b = b->next->next; + } b = c->next, c->next = NULL; 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) else tmp->next = queue->tail; } - else + else { ERROR("out of memory"); + } } /* -->8-- */ @@ -96,8 +97,9 @@ main() queue_init(queue); - for ( int i = 0; i != 10; ++i ) + for ( int i = 0; i != 10; ++i ) { queue_put(queue, i); + } while ( !queue_empty(queue) ) { int i; -- cgit v1.3