Reverse a Linked List

Objec­tive: Reverse the given linked list.

Input: A Linked List

Out­put: 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 imple­men­ta­tion of this problem.



  • Cre­ate 3 nodes, cur­rN­ode, Pre­vN­ode and nextNode.
  • Ini­tial­ize them as cur­rN­ode = head; nextN­ode = null;pre­vN­ode = null;
  • Now keep revers­ing the point­ers one by one till currNode!=null.
     nextNode =; = prevNode;
     prevNode = currNode;
     currNode = nextNode;
  • At the end set head = prevNode;
  • See Exam­ple:
  • Linked List Reversal

    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.


  • Recur­sive Approach:
    • Take 3 nodes as Node ptrOne,Node ptrTwo, Node prevNode
    • Ini­tial­ize them as ptrOne = head;, pre­vN­ode = null.
    • Call reverseRecursion(head,,null)
    • Reverse the ptrOne and ptrTwo
    • Make a recur­sive call for reverseRecursion(,,null)

    Com­plete Code:


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


You may also like...

  • Aman Rustagi
  • Tom Grim­berg

    there is a tiny mis­take of num­ber­ing in the sec­ond stage pic­ture
    of revers­ing the linked list,
    sould be like before: pre­vN­ode = cur­rN­ode; step 3
    cur­rN­ode = nextN­ode; step 4

  • iOSe­Tu­to­ri­als (Sheldon)

    can u really access prev node if it is a singly linked list?

    • iOSe­Tu­to­ri­als (Sheldon)

      I think it should be as easy as:
      cur­rentN­ode = list.head
      while ( != nil) {


  • Paul

    The recur­sive recurse method is flawed. What if the linked list is empty or con­tains only 1 ele­ment? It crashes…

  • rahul1906

    Here is bet­ter way for recursion —

    pub­lic void reverseRecursion(Node curnode,Node pre­vn­ode){
    if(curnode == null){
    System.out.println(“n Reverse Through Recur­sion”);
    Node nextn­ode =; = pre­vn­ode;
    pre­vn­ode = curn­ode;
    curn­ode = nextn­ode;