VOOZH about

URL: https://www.geeksforgeeks.org/dsa/practice-questions-for-linked-list-and-recursion/

⇱ Practice questions for Linked List and Recursion - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Practice questions for Linked List and Recursion

Last Updated : 14 Feb, 2023

Assume the structure of a Linked List node is as follows. 

Explain the functionality of the following C functions.

1. What does the following function do for a given Linked List?

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

2. What does the following function do for a given Linked List? 

fun2() 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 fun2() skips the last node. For Linked List 1->2->3->4->5, fun2() prints 1 3 5 5 3 1. For Linked List 1->2->3->4->5->6, fun2() prints 1 3 5 5 3 1.

Below is a complete running program to test the above functions.

Output: 

 Output of fun1() for list 1->2->3->4->5 
5 4 3 2 1 
Output of fun2() for list 1->2->3->4->5 
1 3 5 5 3 1

Time complexity: O(n)

Auxiliary Space: O(1)


Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above.
 

Comment
Article Tags: