Merge pull request #2 from andrewlalis/andrew

fixed list free function.
This commit is contained in:
Andrew Lalis 2017-05-23 21:26:30 +02:00 committed by GitHub
commit c050a8b916
2 changed files with 10 additions and 13 deletions

View File

@ -67,10 +67,11 @@ Free List node:
de-allocates memory for a list, and all next items recursively. de-allocates memory for a list, and all next items recursively.
*/ */
void TEMPLATE(free,LIST_NODE)(LIST_NODE* list){ void TEMPLATE(free,LIST_NODE)(LIST_NODE* list){
if (list->next != NULL){ while (list->next != NULL){
TEMPLATE(free,LIST_NODE)(list->next); LIST_NODE* next = list->next;
free(list);
list = next;
} }
free(list);
} }
/* /*

16
test.c
View File

@ -26,16 +26,12 @@ int main(int argc, char* argv[]){
push_double_stack(42.5, &s); push_double_stack(42.5, &s);
print_double_stack(s); print_double_stack(s);
float_list* l = new_float_list(5.0, NULL); float_list* l = new_float_list(-1, NULL);
l = add_float_list(6.0, l); printf("Start.\n");
l = add_float_list(7.0, l); for (int i = 0; i < 100000000; i++){
l = add_float_list(8.0, l); l = add_float_list(i*i, l);
printList(l); }
l = insert_float_list(15.5525, 2, l); printf("End.\n");
l = insert_float_list(25, 0, l);
printList(l);
l = remove_float_list(2, l);
printList(l);
free_float_list(l); free_float_list(l);
} }