Reverse a linked list without recursion | Data Structure & Algorithm

Опубликовано: 07 Февраль 2026
на канале: WebTechSchool (WebTechSchool.com)
196
8

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
→temp= curr.next
4-Now change next of current. This is where we reverse the nodes
curr.next = prev
5- Move prev and curr pointer till curr becomes null
→prev = curr
→curr = nex
6-return prev

Source Code : https://github.com/webtechschool/Data...

Company Tag : Amazon, Microsoft, Snapdeal, Adobe (Courtesy : geekforgeeks)