public static Node digui_reverse(Node p) {
if(p!=null && p.next!=null) {
Node next = digui_reverse(p.next);
next.next = p;
p.next = null;
return p;
}
return p;
}
public static Node while_reverse(Node p){
Node pre = null;
Node next = null;
while(p!=null){
next = p.next;
p.next = pre;
pre = p;
p = next;
}
return pre;
}
巧记:
1、只分析两个相邻结点的关系,递归法自然而然就写出来了。
2、循环只要起手记得写pre、next,循环的过程也自然写出来了。