Given a Linked List, display the linked list in reverse without using recursion, stack or modifications to given list.
Input : 1->2->3->4->5->NULL Output :5->4->3->2->1->NULL Input :10->5->15->20->24->NULL Output :24->20->15->5->10->NULL
Below are different solutions that are now allowed here as we cannot use extra space and modify list.
1) Recursive solution to print reverse a linked list. Requires extra space.
2) Reverse linked list and then print. This requires modifications to original list.
3) Stack based solution to print linked list reverse. Push all nodes one by one to a stack. Then one by one pop elements from stack and print. This also requires extra space.
1) Find n = count nodes in linked list. 2) For i = n to 1, do following. Print i-th node using get n-th node function
5 4 3 2 1
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Length of longest palindrome list in a linked list using O(1) extra space
- Reverse a stack without using extra space in O(n)
- Print Reverse a linked list using Stack
- Print reverse of a Linked List without actually reversing
- Print Doubly Linked list in Reverse Order
- An interesting method to print reverse of a linked list
- Print the last k nodes of the linked list in reverse order | Recursive approach
- Print the last k nodes of the linked list in reverse order | Iterative Approaches
- Find pair for given sum in a sorted singly linked without extra space
- Find extra node in the second Linked list
- Can we reverse a linked list in less than O(n)?
- Reverse a linked list
- Clone a linked list with next and random pointer in O(1) space
- Reverse first K elements of given linked list
- Reverse a sublist of linked list
- Reverse a Doubly Linked List
- Reverse even elements in a Linked List
- Reverse a Doubly Linked List | Set-2
- Reverse a Linked List according to its Size
- Reverse a circular linked list