class Node{
int value;
Node next;
public Node(int value){
this.value = value;
}
}
public class LinkReverse {
public static Node reverseV1(Node head){
if(head == null || head.next == null) {
return head;
}
Node pre = null;
Node next = null;
while(head != null) {
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
public static Node reverseV2(Node head){
if(head == null || head.next == null) {
return head;
}
Node reverseNode = reverseV2(head.next);
head.next.next = head;
head.next = null;
return reverseNode;
}
}