diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-05 17:52:04 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-05 18:16:19 +0100 |
commit | c413072aeda26fbe9aee49646b1bd62213236395 (patch) | |
tree | 2dd4b831f721cd15e2d3aea52b500b71fe073498 /linked_list.inc.h | |
parent | Fix up GC a tiny bit. (diff) | |
download | calp-c413072aeda26fbe9aee49646b1bd62213236395.tar.gz calp-c413072aeda26fbe9aee49646b1bd62213236395.tar.xz |
Fix append.
Diffstat (limited to '')
-rw-r--r-- | linked_list.inc.h | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/linked_list.inc.h b/linked_list.inc.h index 7d9452e0..3710bc13 100644 --- a/linked_list.inc.h +++ b/linked_list.inc.h @@ -81,13 +81,14 @@ int DEEP_COPY(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* src ) { } /* - * TODO - * this or cons links wrong, creating infinite loops. - * TODO - * or maybe not + * Adds two linked lists together. + * O(1) time. + * destroys new in the process, but keeps the elements. + * make sure to free(new) after. */ int APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new ) { + LINK(TYPE)* og_new_head = new->head; dest->tail->before->after = new->head->after; new->head->after->before = dest->tail->before; LINK(TYPE)* old_tail = dest->tail; @@ -95,12 +96,7 @@ int APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new ) { dest->length += new->length; free(old_tail); - // free(new->head); - - /* - * TODO `new` can now be handled as an empty husk. - * Somehow it needs to be collected - */ + free(og_new_head); return 0; } |