Reverse a Linked List

Objective: Reverse the given linked list.

Input: A Linked List

Output: Reversed Linked List


Input : ->30->25->20->15->10->5

Reversed : ->5->10->15->20->25->30

NOTE : Click Reverse a Linked List – Part 2 to see the another implementation of this problem.



  • Create 3 nodes, currNode, PrevNode and nextNode.
  • Initialize them as currNode = head; nextNode = null;prevNode = null;
  • Now keep reversing the pointers one by one till currNode!=null.
     nextNode =; = prevNode;
     prevNode = currNode;
     currNode = nextNode;
  • At the end set head = prevNode;
  • See Example:

Linked List Reversal

Note: If Image above is not clear, either zoom your browser or right click on image and open in a new tab.

  • Recursive Approach:
    • Take 3 nodes as Node ptrOne,Node ptrTwo, Node prevNode
    • Initialize them as ptrOne = head;, prevNode = null.
    • Call reverseRecursion(head,,null)
    • Reverse the ptrOne and ptrTwo
    • Make a recursive call for reverseRecursion(,,null)

Complete Code:


Reverse Through Iteration
Original Link List 2 : ->36->35->34->33->32->31
Reverse Through Recursion

7 thoughts on “Reverse a Linked List”

  1. there is a tiny mistake of numbering in the second stage picture
    of reversing the linked list,
    sould be like before: prevNode = currNode; step 3
    currNode = nextNode; step 4

  2. Here is better way for recursion –

    public void reverseRecursion(Node curnode,Node prevnode){
    if(curnode == null){
    System.out.println(“n Reverse Through Recursion”);
    Node nextnode =; = prevnode;
    prevnode = curnode;
    curnode = nextnode;


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.