From 9014bd05172fd8db11dd99251cc541c7656c302f Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 11 Dec 2024 17:27:25 +0100 Subject: [PATCH] modified: src/llist.c modified: src/llist.h --- src/llist.c | 12 +++++++----- src/llist.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/llist.c b/src/llist.c index 5c1a1da..517af41 100644 --- a/src/llist.c +++ b/src/llist.c @@ -15,6 +15,7 @@ llist *llistNew(void *data, int (*cmpFN)(void *a, void *b)) { r->data = data; r->prev = NULL; r->next = NULL; + r->tail = r; } return r; } @@ -22,11 +23,11 @@ llist *llistNew(void *data, int (*cmpFN)(void *a, void *b)) { /*return last node of linked list; */ llist *llistTail(llist *head) { - llist *tail = head; - while (tail->next != NULL) { - tail = tail->next; - } - return tail; + // llist *tail = head; + // while (tail->next != NULL) { + // tail = tail->next; + // } + return head->tail; } /* creates new node from data and appends it to tail @@ -40,6 +41,7 @@ llist *llistAppend(llist *head, void *data) { new->next = NULL; new->prev = tail; tail->next = new; + head->tail = new; } return new; } diff --git a/src/llist.h b/src/llist.h index 42fdda5..49c206f 100644 --- a/src/llist.h +++ b/src/llist.h @@ -6,6 +6,7 @@ typedef struct llist { void *data; struct llist *next; struct llist *prev; + struct llist *tail; int (*cmpFn)(void *a, void *b); // function that compares data } llist;