fixed list free function.
This commit is contained in:
parent
69daec541c
commit
c1375f3882
|
@ -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
16
test.c
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue