From 21e05fda58bdb6a3843fb135869455553493f7e1 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Wed, 1 Jun 2022 11:02:45 +0200 Subject: [PATCH] impl insert and merge --- List.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/List.h b/List.h index 8155afa..b94f4aa 100644 --- a/List.h +++ b/List.h @@ -78,8 +78,12 @@ int length(List *list) { return _length(list->head); } -void insert(List *list, int position) { +void insert(List *list, void* elem, int position) { + Node* insertpos = _traverseToPos(list->head, position); + Node* newnode = _newNode(insertpos->next, insertpos, elem); + insertpos->next = newnode; + insertpos->next->next->prev = newnode; } void delete(List *list, int position) { @@ -113,16 +117,19 @@ void deleteList(List *list) { free(list); } +Node *first(List *list) { + return list->head; +} + +Node *last(List *list) { + return _traverseToLast(list->head); +} + List *merge(List *list1, List *list2) { - return NULL; -} - -void *first(List *list) { - return list->head->dta; -} - -void *last(List *list) { - return _traverseToLast(list->head)->dta; + Node* end = last(list1); + end->next = list2->head; + list2->head->prev = end; + return list1; } void print(List *list, char *typeFormatter) {