class Node{
int value;
Node next;
Node ref;
public Node(int value){
this.value = value;
}
}
public class ReverseList {
public static Node reverseList(Node head){
Node oldNext = null;
Node newNext = null;
while(head.next!=null){
oldNext = head.next;
head.next = newNext;
newNext = head;
head = oldNext;
}
head.next = newNext;
return head;
}
public static Node reverseDoubleList(Node head){
Node oldNext = null;
Node ref = null;
while(head.next!=null){
oldNext = head.next;
head.next = ref;
head.ref = oldNext;
ref = head;
head = oldNext;
}
head.next = ref;
head.ref = null;
return head;
}
}