consider two functions for free()ing a linked list:
Code:
void freelist(struct node *root)
{
struct node *index, *save;
if (root != NULL)
for (index=root; index!=NULL; index=save)
{
save=index->next;
free(index);
}
}
second:
Code:
void freelist(struct node **root)
{
struct node *save;
if (*root != NULL)
for ( ; *root != NULL; *root = save)
{
save = (*root)->next;
free(*root);
}
}
when i call the first function to free the list and then try to print it i get something like:
Code:
134518592
134518608
134518624
134518640
134518656
134518672
134518688
134518704
134518720
what's that? the memory addresses of the data in the nodes? but they were freed already.
when trying to printf the list after the call to the second freelist function, i simply get 'Empty List'.
So, why is the output different? which function should i use, or are they both ok?