xinrong2019 / xinrong2019.github.io

My Blog
https://xinrong2019.github.io
1 stars 1 forks source link

20190609 数据结构和算法之循环双向链表 #68

Open xinrong2019 opened 5 years ago

xinrong2019 commented 5 years ago
public class DoubleNode {
    //上一个节点
    DoubleNode pre=this;
    //下一个节点
    DoubleNode next=this;
    //节点数据
    int data;

    public DoubleNode(int data) {
        this.data=data;
    }

    //增节点
    public void after(DoubleNode node) {
        //原来的下一个节点
        DoubleNode nextNext = next;
        //把新节点做为当前节点的下一个节点
        this.next=node;
        //把当前节点做新节点的前一个节点
        node.pre=this;
        //让原来的下一个节点作新节点的下一个节点
        node.next=nextNext;
        //让原来的下一个节点的上一个节点为新节点
        nextNext.pre=node;
    }

    //下一个节点
    public DoubleNode next() {
        return this.next;
    }

    //上一个节点
    public DoubleNode pre() {
        return this.pre;
    }

    //获取数据
    public int getData() {
        return this.data;
    }

}