package Nodepackage; public class DoubleNode { int DN; DoubleNode pre = this; DoubleNode next = this;//因为只有一个节点的时候,上一个和下一个都是他自己 public DoubleNode(int DN){ this.DN = DN; } //添加节点 public DoubleNode after(DoubleNode next){ next.pre = this; next.next = this.next; this.next.pre = next;//修改当前节点的下一个节点的上个节点为新节点 this.next = next;//修改当前节点的下一个节点为添加的新节点 return next; } public int getDate(){ return this.DN; } //获取下一个节点 public int next(){ return next.getDate(); } //获取上一个节点 public int pre(){ return pre.getDate(); } //删除当前节点 public void removeNode(){ this.pre.next = this.next; this.next.pre = this.pre; } //遍历所有节点利用的是地址进行遍历的,如果是同一个地址则就停止, public void show(){ DoubleNode cur = this; DoubleNode nex = cur; while (true){ System.out
java学习笔记:双向循环链表及遍历
最新推荐文章于 2023-05-12 19:53:16 发布