diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-09-02 15:09:05 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-09-02 15:09:05 +0200 |
| commit | 0838786720429bc87ac654f5688c628e1b8f684b (patch) | |
| tree | 4b56ec20c11ee608f171e4155a73f70441b47506 /list.c | |
| parent | e7cc0d492d67b798a44cb45dabc6893e31394988 (diff) | |
| parent | 234d9500e3e2462a5404d5e675fa5a7b8038d059 (diff) | |
| download | data-structures-0838786720429bc87ac654f5688c628e1b8f684b.tar.gz data-structures-0838786720429bc87ac654f5688c628e1b8f684b.tar.bz2 data-structures-0838786720429bc87ac654f5688c628e1b8f684b.zip | |
Merge branch 'feature-list-insert'
Diffstat (limited to 'list.c')
| -rw-r--r-- | list.c | 28 |
1 files changed, 28 insertions, 0 deletions
| @@ -32,6 +32,22 @@ list_add(struct list_item *next, T data) | |||
| 32 | return new_item; | 32 | return new_item; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void | ||
| 36 | list_insert_next(struct list_item *list, T data) | ||
| 37 | { | ||
| 38 | struct list_item *new_item; | ||
| 39 | |||
| 40 | new_item = malloc(sizeof *new_item); | ||
| 41 | if ( new_item != NULL ) { | ||
| 42 | new_item->data = data; | ||
| 43 | |||
| 44 | new_item->next = list->next; | ||
| 45 | list->next = new_item; | ||
| 46 | } | ||
| 47 | else | ||
| 48 | ERROR("out of memory"); | ||
| 49 | } | ||
| 50 | |||
| 35 | struct list_item * | 51 | struct list_item * |
| 36 | list_delete(struct list_item *list, T data) | 52 | list_delete(struct list_item *list, T data) |
| 37 | { | 53 | { |
| @@ -56,6 +72,18 @@ list_delete(struct list_item *list, T data) | |||
| 56 | return list; | 72 | return list; |
| 57 | } | 73 | } |
| 58 | 74 | ||
| 75 | void | ||
| 76 | list_delete_next(struct list_item *list) | ||
| 77 | { | ||
| 78 | if ( list->next != NULL ) { | ||
| 79 | struct list_item *temp = list->next; | ||
| 80 | |||
| 81 | list->next = list->next->next; | ||
| 82 | |||
| 83 | free(temp); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 59 | size_t | 87 | size_t |
| 60 | list_length(struct list_item *list) | 88 | list_length(struct list_item *list) |
| 61 | { | 89 | { |
