Vote count:
0
I am trying to remove the last two in a linear linked list recursively. I do not understand why this code is seg faulting. Please help. Is there a better or more correct way to remove the last two nodes recursively?
int remove(node * & head)
{
if(!head)
return 0;
if(!head -> next)
{
delete head;
head = NULL;
}
if(!head -> next -> next)
{
return remove(head -> next);
delete head;
head = NULL;
}
return remove(head -> next);
}
asked 25 secs ago
Removing last two nodes recursively
Aucun commentaire:
Enregistrer un commentaire