双向链表
package hash_map.link; //双向链表 /** * 每个节点由3部分组成:指向前一个节点的引用,数据区,指向后一个节点的引用 * */ public class TwoWay { Node first; Node last; class Node{ long data; Node pre; Node next; public Node(long data) { this.data = data; } } //向头结点插入元素 public void insertFirst(long data){ Node node = new Node(data); if (first == null) { first = node; }else { first.pre = node; node.next = first; } last = node; } //向尾节点插入元素 public void insertLast(long data){ Node node = new Node(data); if (first == null) { first = node; }else { last.next = node; node.pre = last; } last = node; } public static void main(String[] args) { } }