For the life of me I can’t figure out how to delete an entire linked list using recursion where the deletion occurs after the recursive call. I tried this:
void remove_nodes(node * &head)
{
if (!head)
return;
remove_nodes(head->next);
delete head;
}
The node struct is simply:
struct node
{
int data;
node * next;
};
When I use the function above and then display the list, it is still there but with garbage data. I don’t understand what I could be doing wrong.