Question: This is a recursive function to delete all even nodes from a linked list. node *deleteEven(node *head) if (head == NULL) return head; if (head->data
This is a recursive function to delete all even nodes from a linked list.
node *deleteEven(node *head)
if (head == NULL)
return head;
if (head->data % 2 == 0)
{
node *temp = head;
free(temp);
return deleteEven(head->next);
}
else
{
head->next = deleteEven(head->next);
return head;
}
}
What is the purpose of heaving to set "head->next = deleteEven(head->next);" instead of just having "head = head->next;" in one of the lines above and just calling "deleteEven(head->next);"?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
