双向链表(双链表)是链表的一种,双链表也是由节点组成,它的每个数据结点中都有两个指针,分别指向后继节点和前驱节点。
借图说话:图片来自于https://www.cnblogs.com/rongweijun/p/8072677.html,感谢大神的图片。
其代码如下:
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 void remove(DoubleNode node){ //删节点
DoubleNode nnext=node.next;
this.next=nnext;
nnext.pre=this.next;
}
}