Skip to content

Instantly share code, notes, and snippets.

@arjunrao87
Created December 21, 2014 14:52
Show Gist options
  • Save arjunrao87/1a5396111f474b708cce to your computer and use it in GitHub Desktop.
Save arjunrao87/1a5396111f474b708cce to your computer and use it in GitHub Desktop.
Reverse linked list
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