public static Node reverseList (Node head) {
Node pre = null;
Node help = null;
while (head != null) {
help = head.next;
head.next = pre;
pre = head;
head = help;
}
return pre;
}
双向链表:
public static DoubleNode reverseList(DoubleNode head) {
DoubleNode pre = null;
DoubleNode help = null;
while (head != null) {
help = head.next;
head.next = pre;
head.last = help;
pre = head;
head = help;
}
return pre;
}