/**
* 反转链表
* @author MA
*
*/
public class Main {
static class Node{
int val;
Node next;
public Node(int val){
this.val = val;
}
}
public static Node reverseList(Node head){
if(head.next == null){
return null;
}
Node node = head;
Node frontnode = null;
Node rhead = null;
Node next = null;
while(node != null){
next = node.next;
if(node.next == null){
rhead = node;
}
node.next = frontnode;
frontnode = node;
node = node.next;
}
return rhead;
}
}