Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What does the following function do for a given Linked List with first node as h

ID: 3558475 • Letter: W

Question

What does the following function do for a given Linked List with 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 lists
(B) Prints all nodes of linked list in reverse order
(C) Prints alternate nodes of Linked List
(D) Prints alternate nodes in reverse order

void fun1(struct node* head)

{

  if(head == NULL)

    return;

   

  fun1(head->next);

  printf("%d ", head->data);

}

Explanation / Answer

Answer: (B)

Explanation: fun1() prints the given Linked List in reverse manner. For Linked List 1->2->3->4->5, fun1() prints 5->4->3->2->1.