链表的反转
`package class03.yumx03;
public class Code1_ReverseList {
public static Node reverseNode(Node head) {
Node pre = null;
Node next;
while (head != null) {
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
public static DoubleNode reverseDoubleNode(DoubleNode head) {
DoubleNode pre = null;
DoubleNode next;
while (head != null) {
next = head.next;
head.next = pre;
head.pre = next;
pre = head;
head = next;
}
return pre;
}
}
class Node {
public Integer value;
public Node next;
public Node(Integer value) {
this.value = value;
}
}
class DoubleNode {
public Integer value;
public DoubleNode pre;
public DoubleNode next;
public DoubleNode(Integer value) {
this.value = value;
}
}
`

浙公网安备 33010602011771号