Skip to content
Related Articles

Related Articles

Data Structures | Linked List | Question 6
  • Difficulty Level : Medium
  • Last Updated : 03 Feb, 2013

What is the output of following function for start pointing to first node of following linked list?

1->2->3->4->5->6




void fun(struct node* start)
{
  if(start == NULL)
    return;
  printf("%d  ", start->data); 
   
  if(start->next != NULL )
    fun(start->next->next);
  printf("%d  ", start->data);
}

(A) 1 4 6 6 4 1
(B) 1 3 5 1 3 5
(C) 1 2 3 5
(D) 1 3 5 5 3 1


Answer: (D)

Explanation: fun() prints alternate nodes of the given Linked List, first from head to end, and then from end to head. If Linked List has even number of nodes, then skips the last node.

My Personal Notes arrow_drop_up
Recommended Articles
Page :