/**
* 单链表反转
* @param node
* @return
*/
public static Node reverse(Node node){
System.out.println("head:"+node.toString());
if(node == null || node.getNext() == null){
return node;
}
Node temp = node.getNext();
System.out.println("temp:"+temp.toString());
Node newNode = reverse(node.getNext());
temp.setNext(node);
node.setNext(null);
return newNode;
}
网友评论