From 4b3ab034720dc4d5afda8db866de96caf2aa1c29 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Thu, 27 Aug 2020 08:26:59 +0200 Subject: zwei neue Funktionen, um das nächste Element einer Liste hinzuzufügen oder zu löschen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/list.c b/list.c index 18465b0..fb21779 100644 --- a/list.c +++ b/list.c @@ -32,6 +32,23 @@ list_add(struct list_item *next, T data) return new_item; } +void +list_insert_next(struct list_item *node, T data) +{ + struct list_item *new_item; + + // TODO: Debuggen und nochmal richtig drüber nachdenken! + new_item = malloc(sizeof *new_item); + if ( new_item != NULL ) { + new_item->next = node->next; + new_item->data = data; + + node->next = new_item; + } + else + ERROR("out of memory"); +} + struct list_item * list_delete(struct list_item *list, T data) { @@ -56,6 +73,19 @@ list_delete(struct list_item *list, T data) return list; } +void +list_delete_next(struct list_item *list) +{ + // TODO: Debuggen und nochmal richtig drüber nachdenken! + if ( list->next != NULL ) { + struct list_item *temp = list->next; + + list->next = list->next->next; + + free(temp); + } +} + size_t list_length(struct list_item *list) { -- cgit v1.3