链表的反转

`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;
}

}
`

posted @ 2023-07-18 08:42  余明星  阅读(21)  评论(0)    收藏  举报