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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!