How to reverse a Singly Linked List iteratively and recursively

Linked List is a data structure that possess following properties:

  • Elements can be inserted indefinitely.
  • They allow sequential access to elements while arrays allow random access


In this article,  I have provided solutions coding for the following:

  • Reversing a singly linked list by using recursion – Recursive Reverse
  • Reversing a singly linked list by using iteration – Iterative Reverse.

Java Implementation Code:


 * @author Kushal Paudyal
 * Created On -  Feb 28, 2014
 * Last Modified On - Feb 28, 2014
public class LinkedListReverse {
	public static void main(String args[]) {
		//Preparing some linked list structure
		LinkedList linkedList = new LinkedList(5); = new LinkedList(4); = new LinkedList(3); = new LinkedList(2); = new LinkedList(1);

		System.out.println("Original Linked List: " + linkedList.toString());

		//recursively reverse and print
		linkedList = recursiveReverse(linkedList);
		System.out.println("Recursively Reversed List: "
				+ linkedList.toString());

		//iteratively reverse and print
		linkedList = iterativeReverse(linkedList);
		System.out.println("Iteratively Recursed to Original: "
				+ linkedList.toString());

	 * This method uses recursive method to reverse a singly linked list.
	public static LinkedList recursiveReverse(LinkedList linkedList) {

		// check for empty or size 1 linked list. This is a base condition to
		// terminate recursion.
		if (linkedList == null || == null) {
			return linkedList;

		LinkedList remainingReverse = recursiveReverse(;

		// update the tail as beginning
		LinkedList current = remainingReverse;
		while ( != null) {
			current =;

		// assign the head as a tail = linkedList; = null;

		return remainingReverse;

	 * This method uses iterative approach to reverse a singly linked list.
	public static LinkedList iterativeReverse(LinkedList linkedList) {

			return linkedList;

		LinkedList prevNode, currNode, nextNode;
		prevNode = null;
		nextNode = null;
		currNode = linkedList;

		while (currNode != null) {
			nextNode =; = prevNode;
			prevNode = currNode;
			currNode = nextNode;

		return prevNode;

 * Custom Linked List representation class
class LinkedList {
	public LinkedList next;
	public int value;

	public LinkedList(int value) {
		this.value = value; = null;

	public String toString() {

		String data = "";
		LinkedList current = this;
		do {
			data += current.value + ",";
			current =;
		} while (current != null);

		return data;

Output of running above program:

Original Linked List: 5,4,3,2,1,
Recursively Reversed List: 1,2,3,4,5,
Iteratively Recursed to Original: 5,4,3,2,1,