Data Structures | Linked List | Question 6

3

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.

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:



3 Average Difficulty : 3/5.0
Based on 1 vote(s)