Open In App
Related Articles

Data Structures | Linked List | Question 6

Improve Article
Save Article
Like Article

What is the output of following function in which start is pointing to the first node of the following linked list 1->2->3->4->5->6 ?


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


1 4 6 6 4 1


1 3 5 1 3 5


1 2 3 5


1 3 5 5 3 1

Answer: (D)


The function prints the data of the current node and then recursively calls itself with the second next node (i.e., start->next->next).

So, it prints the data of every alternate node of the linked list i.e 1 3 5, and then, since the next->next of 5 is null, it returns and prints the data of the current node, so it then prints 5 3 1.

Therefore, for the given linked list 1->2->3->4->5->6, the function would print 1 3 5 5 3 1.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated : 03 Feb, 2013
Like Article
Save Article
Similar Reads
Complete Tutorials