Question of quiz

Predict the output that the following code gives for a linked list given as 1->2->3->4->5->6

void fun(node* start)
{
if(start == NULL)
return;
cout<data<<" “;
if(start->next != NULL )
fun(start->next->next);
cout<data<<” ";
}

how its printing 1 3 5 5 3 1

hello @nilotpal

first we are printing current data then

we are calling same function on start->next->next which will recusively print that node and its subsequent node recursively.

and then while coming back

we are again printing the data thats why then output that we are getting is
1 3 5 5 2 1