Created
December 21, 2014 14:52
-
-
Save arjunrao87/1a5396111f474b708cce to your computer and use it in GitHub Desktop.
Reverse linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node{ | |
private int data; | |
private Node next; | |
public Node( int data ){ | |
this.data = data; | |
this.next = null; | |
} | |
public void setNext( Node next ){ | |
this.next = next; | |
} | |
public Node getNext(){ | |
return this.next; | |
} | |
public int getData(){ | |
return this.data; | |
} | |
} | |
public class ReverseLinkedList{ | |
public void reverseLL( Node head ){ | |
Node previous; | |
Node next; | |
Node current = head; | |
while( current != null ){ | |
next = current.getNext(); | |
current.setNext( prev ); | |
prev = current; | |
current = next; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment