I'm a little confused on the order of this function. It takes in a struct node pointer and free's each node until there are no nodes left (I think). What I don't understand is if we recursively call recursive_destroyer(), I don't understand how the function will reach free(head). Same with the destroy_list() function. Doesn't calling the recursive function restart the function? Here is the code: Also, Node and LinkedList are structs that aren't included here, just for reference.
node *recursive_destroyer(node *head) // takes in node and deletes each node
{
if (head == NULL) // if there are no nodes
return NULL;
recursive_destroyer(head->next); // cycle through each node
free(head);
return NULL;
}
LinkedList *destroy_list(LinkedList *list)
{
if (list == NULL)
return NULL;
recursive_destroyer(list->head);
free(list);
return NULL;
}