Reverse a Linked List
Problem
Reverse a singly linked list.
For example:
Thought Process
To reverse a LinkedList, we need to reverse one node at a time. We will start with a variable
current
which will initially point to the head of the LinkedList and a variableprevious
which will point to the previous node that we have processed; initiallyprevious
will point tonull
.In a stepwise manner, we will reverse the
current
node by pointing it to theprevious
before moving on to the next node. Also, we will update theprevious
to always point to the previous node that we have processed.
Solution
Last updated
Was this helpful?