diff options
Diffstat (limited to 'list.c')
| -rw-r--r-- | list.c | 16 |
1 files changed, 8 insertions, 8 deletions
| @@ -25,7 +25,7 @@ list_add(struct list_item *next, T data) | |||
| 25 | struct list_item *new_item; | 25 | struct list_item *new_item; |
| 26 | 26 | ||
| 27 | new_item = malloc(sizeof *new_item); | 27 | new_item = malloc(sizeof *new_item); |
| 28 | if ( new_item != NULL ) { | 28 | if ( new_item ) { |
| 29 | new_item->data = data; | 29 | new_item->data = data; |
| 30 | new_item->next = next; | 30 | new_item->next = next; |
| 31 | } | 31 | } |
| @@ -44,7 +44,7 @@ list_insert_next(struct list_item *list, T data) | |||
| 44 | struct list_item *new_item; | 44 | struct list_item *new_item; |
| 45 | 45 | ||
| 46 | new_item = malloc(sizeof *new_item); | 46 | new_item = malloc(sizeof *new_item); |
| 47 | if ( new_item != NULL ) { | 47 | if ( new_item ) { |
| 48 | new_item->data = data; | 48 | new_item->data = data; |
| 49 | new_item->next = list->next; | 49 | new_item->next = list->next; |
| 50 | list->next = new_item; | 50 | list->next = new_item; |
| @@ -76,7 +76,7 @@ list_delete(struct list_item *list, T data) | |||
| 76 | } | 76 | } |
| 77 | prev = p; | 77 | prev = p; |
| 78 | } | 78 | } |
| 79 | #if LIST_REPORT_ERROR | 79 | #ifdef LIST_REPORT_ERROR |
| 80 | ERROR("data not found"); | 80 | ERROR("data not found"); |
| 81 | #endif | 81 | #endif |
| 82 | return list; | 82 | return list; |
| @@ -87,7 +87,7 @@ list_delete(struct list_item *list, T data) | |||
| 87 | void | 87 | void |
| 88 | list_delete_next(struct list_item *list) | 88 | list_delete_next(struct list_item *list) |
| 89 | { | 89 | { |
| 90 | if ( list->next != NULL ) { | 90 | if ( list->next ) { |
| 91 | struct list_item *temp = list->next; | 91 | struct list_item *temp = list->next; |
| 92 | 92 | ||
| 93 | list->next = list->next->next; | 93 | list->next = list->next->next; |
| @@ -119,7 +119,7 @@ list_copy(struct list_item *list) | |||
| 119 | 119 | ||
| 120 | for ( ; list; list = list->next ) { | 120 | for ( ; list; list = list->next ) { |
| 121 | *p = malloc(sizeof **p); | 121 | *p = malloc(sizeof **p); |
| 122 | if ( *p != NULL ) { | 122 | if ( *p ) { |
| 123 | (*p)->data = list->data; // copy elements | 123 | (*p)->data = list->data; // copy elements |
| 124 | p = &(*p)->next; | 124 | p = &(*p)->next; |
| 125 | } | 125 | } |
| @@ -164,7 +164,7 @@ list_merge(struct list_item *a, struct list_item *b) | |||
| 164 | struct list_item dummy = { .next = NULL }; | 164 | struct list_item dummy = { .next = NULL }; |
| 165 | struct list_item *head = &dummy, *c = head; | 165 | struct list_item *head = &dummy, *c = head; |
| 166 | 166 | ||
| 167 | while ( a != NULL && b != NULL ) | 167 | while ( a && b ) |
| 168 | if ( a->data < b->data ) { | 168 | if ( a->data < b->data ) { |
| 169 | c->next = a, c = a, a = a->next; | 169 | c->next = a, c = a, a = a->next; |
| 170 | } | 170 | } |
| @@ -172,7 +172,7 @@ list_merge(struct list_item *a, struct list_item *b) | |||
| 172 | c->next = b, c = b, b = b->next; | 172 | c->next = b, c = b, b = b->next; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | c->next = (a != NULL) ? a : b; | 175 | c->next = a ? a : b; |
| 176 | 176 | ||
| 177 | return head->next; | 177 | return head->next; |
| 178 | } | 178 | } |
| @@ -188,7 +188,7 @@ list_sort(struct list_item *c) | |||
| 188 | struct list_item *a = c, | 188 | struct list_item *a = c, |
| 189 | *b = c->next; | 189 | *b = c->next; |
| 190 | 190 | ||
| 191 | while ( b != NULL && b->next != NULL ) { | 191 | while ( b && b->next ) { |
| 192 | c = c->next, b = b->next->next; | 192 | c = c->next, b = b->next->next; |
| 193 | } | 193 | } |
| 194 | 194 | ||
