diff --git a/source/handylist.h b/source/handylist.h index 527a73d..582aecc 100644 --- a/source/handylist.h +++ b/source/handylist.h @@ -67,10 +67,11 @@ Free List node: de-allocates memory for a list, and all next items recursively. */ void TEMPLATE(free,LIST_NODE)(LIST_NODE* list){ - if (list->next != NULL){ - TEMPLATE(free,LIST_NODE)(list->next); + while (list->next != NULL){ + LIST_NODE* next = list->next; + free(list); + list = next; } - free(list); } /* diff --git a/test.c b/test.c index 2efd2fd..acd4997 100644 --- a/test.c +++ b/test.c @@ -26,16 +26,12 @@ int main(int argc, char* argv[]){ push_double_stack(42.5, &s); print_double_stack(s); - float_list* l = new_float_list(5.0, NULL); - l = add_float_list(6.0, l); - l = add_float_list(7.0, l); - l = add_float_list(8.0, l); - printList(l); - l = insert_float_list(15.5525, 2, l); - l = insert_float_list(25, 0, l); - printList(l); - l = remove_float_list(2, l); - printList(l); + float_list* l = new_float_list(-1, NULL); + printf("Start.\n"); + for (int i = 0; i < 100000000; i++){ + l = add_float_list(i*i, l); + } + printf("End.\n"); free_float_list(l); }