Get Mystery Box with random crypto!

Reverse a Singly Linked List using Recursion Given pointer to | Cse interview questions

Reverse a Singly Linked List using Recursion

Given pointer to the head node of a linked list, the task is to reverse the linked list using recursion. We need to reverse the list by changing the links between nodes.

Examples :

Input 1 :
1->2->3->4->NULL

Output 1 :
4->3->2->1->NULL

Explanation 1 :
Input list in reversed order is 4->3->2->1->NULL


Input 2 : 1->NULL

Output 2 : 1->NULL

Explanation 3 :
There is only one element in the list ie 1, so reversed ordered ilst is same as input list.

Topic : Linked Lists

Reference -> GeeksforGeeks

Solution -> GeeksforGeeks article 1, article 2

Asked in Paytm

Join our Official Channel @cseinterview