aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--list-tail-node.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/list-tail-node.c b/list-tail-node.c
index c939b8d..158fae8 100644
--- a/list-tail-node.c
+++ b/list-tail-node.c
@@ -89,6 +89,50 @@ list_pop_front(struct list *list, T *data)
89 } 89 }
90} 90}
91 91
92void
93list_insert_next(struct list *list, struct list_node *node, T data)
94{
95 if ( node == NULL ) { // Am Anfang einfügen
96 list_push_front(list, data);
97 }
98 else {
99 struct list_node *new_node = create_node(node->next, data);
100
101 if ( new_node != NULL ) {
102 if ( node->next == NULL ) { // Am Ende einfügen
103 list->tail = new_node;
104 }
105 node->next = new_node;
106 }
107 else {
108 ERROR("out of memory");
109 }
110 }
111}
112
113void
114list_delete_next(struct list *list, struct list_node *node, T *data)
115{
116 if ( node == NULL ) { // Am Anfang entfernen
117 list_pop_front(list, data);
118 }
119 else {
120 if ( node->next != NULL ) {
121 struct list_node *old_node = node->next;
122 node->next = node->next->next;
123
124 if ( node->next == NULL ) {
125 list->tail = node;
126 }
127
128 if ( data != NULL ) {
129 *data = old_node->data;
130 }
131 free(old_node);
132 }
133 }
134}
135
92bool 136bool
93list_empty(struct list *list) 137list_empty(struct list *list)
94{ 138{