This problem can be solved in 2 ways. It then recursively applies the same division until it reaches the last node, at that point whole linked list, is reversed. Iterative solution. Now let’s create a program for reversing the linked list. Recursively reverse linked list. And initialize as shown below: prev = NULL Curr = head Temp = NULL. Solution:. Live Demo There can be two ways to create the program, one is iterative and the other one is recursive. Working with the recursive assumption. But must stop just before the end of the node, and we should have total 3 nodes in hand. First, to make a recursive algorithm, we need to understand how the present data in the list is being held. In this solution, we need 3 pointers. To reverse the linked list, we only need to reverse the pointers directions of the list. Program for Reverse a linked list (tail-recursive approach) Example. In recursive approach, we need to move to the end of the node. The recursive version of this problem is slightly trickier and the key is to work backwards. Hot Network Questions Probability after n steps C Linked List Code Style Limit if the limit is a function Is this a Phishing attempt? It divides the list into two parts first node and rest of the list, and then link rest to head in reverse order. Why did Marty McFly need to look up Doc Brown's address in 1955? From the current situation with a partially reversed linked list, we can achieve a fully reversed linked list with the following operations: Iterative; Recursive; 1. Problem: To test both data structure and the recursion concept, a wonderful and confusing interview question asked to experienced people is “Reverse a linked list using recursion”.. Assume that the rest of the list had already been reversed by Recursion, now how do I reverse the front… Save my name, email, and website in this browser for the next time I comment. So in every loop, we require a temporary pointer variable to save the start location while the list is being reversed. So we iterate and reverse the list until the current is null. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL. Now we need to do the rest of the work to have the whole linked list reversed. Reverse a singly linked list. This assumption that reverse() works for a subset of our linked list (but not the whole thing) has gotten us pretty far.