What does the following function do for a given Linked List with the first…
2025
What does the following function do for a given Linked List with the first node as head?
void fun1(struct node* head)
{
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data);
}- A.
Prints all nodes of linked list
- B.
Prints all nodes of linked list in reverse order
- C.
Prints alternate nodes of linked list
- D.
Prints alternate nodes in reverse order
Attempted by 125 students.
Show answer & explanation
Correct answer: B
This function uses recursion to traverse the linked list. It first calls itself recursively until it reaches the end of the list (when head is NULL). Then, as each recursive call returns, it prints the current node's data. This means nodes are printed in reverse order from head to tail.