diff --git a/linked-list.c b/linked-list.c index a6e18e2..68f968a 100644 --- a/linked-list.c +++ b/linked-list.c @@ -50,6 +50,8 @@ void list_print(list_t * list) { void list_add(list_t * list, list_node_t * item) { list_node_t *cur; + assert(item->next == NULL); + if (list_empty(list)) { list->head = item; } else { @@ -143,6 +145,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < howmany; i++) { list_node_t *newnode = malloc(sizeof(list_node_t)); newnode->data = i; + newnode->next = NULL; list_add(foolist, newnode); } @@ -200,6 +203,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < howmany2; i++) { list_node_t *newnode = malloc(sizeof(list_node_t)); newnode->data = i; + newnode->next = NULL; list_add(foolist, newnode); }