aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-09-02 15:09:05 +0200
committerThomas Schmucker <ts@its1.de>2020-09-02 15:09:05 +0200
commit0838786720429bc87ac654f5688c628e1b8f684b (patch)
tree4b56ec20c11ee608f171e4155a73f70441b47506
parente7cc0d492d67b798a44cb45dabc6893e31394988 (diff)
parent234d9500e3e2462a5404d5e675fa5a7b8038d059 (diff)
downloaddata-structures-0838786720429bc87ac654f5688c628e1b8f684b.tar.gz
data-structures-0838786720429bc87ac654f5688c628e1b8f684b.tar.bz2
data-structures-0838786720429bc87ac654f5688c628e1b8f684b.zip
Merge branch 'feature-list-insert'
-rw-r--r--list.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/list.c b/list.c
index 18465b0..da0c702 100644
--- a/list.c
+++ b/list.c
@@ -32,6 +32,22 @@ list_add(struct list_item *next, T data)
32 return new_item; 32 return new_item;
33} 33}
34 34
35void
36list_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
35struct list_item * 51struct list_item *
36list_delete(struct list_item *list, T data) 52list_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
75void
76list_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
59size_t 87size_t
60list_length(struct list_item *list) 88list_length(struct list_item *list)
61{ 89{