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
- Length of longest palindrome list in a linked list using O(1) extra space
- Print reverse of a Linked List without actually reversing
- Print Reverse a linked list using Stack
- Reverse a stack without using extra space in O(n)
- An interesting method to print reverse of a linked list
- Print Doubly Linked list in Reverse Order
- 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
- Can we reverse a linked list in less than O(n)?
- Reverse a linked list
- Reverse a Linked List according to its Size
- Reverse a Doubly Linked List
- Reverse a sublist of linked list
- Reverse a circular linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.