Given a singly linked list, write a code to reverse a linked list. In this tutorial, you are going to learn how to reverse a linked list in java using iterative approach.
For example –
Input linked list.
15 -> 9 -> 8 -> 5 -> NULL
When we reverse this linked list then the output is given below.
5 -> 8 -> 9 -> 15 -> NULL
In input linked list, head points to a node whose value is 15 but when it’s reversed the head points to a node whose value is 5.