parent
a88262bb28
commit
9014bd0517
12
src/llist.c
12
src/llist.c
|
@ -15,6 +15,7 @@ llist *llistNew(void *data, int (*cmpFN)(void *a, void *b)) {
|
||||||
r->data = data;
|
r->data = data;
|
||||||
r->prev = NULL;
|
r->prev = NULL;
|
||||||
r->next = NULL;
|
r->next = NULL;
|
||||||
|
r->tail = r;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +23,11 @@ llist *llistNew(void *data, int (*cmpFN)(void *a, void *b)) {
|
||||||
/*return last node of linked list;
|
/*return last node of linked list;
|
||||||
*/
|
*/
|
||||||
llist *llistTail(llist *head) {
|
llist *llistTail(llist *head) {
|
||||||
llist *tail = head;
|
// llist *tail = head;
|
||||||
while (tail->next != NULL) {
|
// while (tail->next != NULL) {
|
||||||
tail = tail->next;
|
// tail = tail->next;
|
||||||
}
|
// }
|
||||||
return tail;
|
return head->tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* creates new node from data and appends it to 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->next = NULL;
|
||||||
new->prev = tail;
|
new->prev = tail;
|
||||||
tail->next = new;
|
tail->next = new;
|
||||||
|
head->tail = new;
|
||||||
}
|
}
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ typedef struct llist {
|
||||||
void *data;
|
void *data;
|
||||||
struct llist *next;
|
struct llist *next;
|
||||||
struct llist *prev;
|
struct llist *prev;
|
||||||
|
struct llist *tail;
|
||||||
int (*cmpFn)(void *a, void *b); // function that compares data
|
int (*cmpFn)(void *a, void *b); // function that compares data
|
||||||
} llist;
|
} llist;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue