Reverse a linked list without recursion | Data Structure & Algorithm

preview_player
Показать описание
Reverse a linked list given a reference to head of the list.

Algorithm :
1 - Initialize two pointers prev as NULL, curr as head
2- Iterate trough the linked list. In loop, do following.
3- Store the current node's next reference in a Temporary node
4-Now change next of current. This is where we reverse the nodes
5- Move prev and curr pointer till curr becomes null
→prev = curr
→curr = nex
6-return prev

Company Tag : Amazon, Microsoft, Snapdeal, Adobe (Courtesy : geekforgeeks)
Рекомендации по теме
welcome to shbcf.ru