java数据结构-双向循环链表实现

package com.node;

/**
* @auther 付强
* @date 2020/2/14 - 13:32
*/
public class DoubleNode {
//上一个节点(等于this)保证循环
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;
}

}

猜你喜欢

转载自www.cnblogs.com/fuqiang-java/p/12309186.html