使用Java语言实现了一个双链表,可进行数据元素的增、删、查。
代码实现如下:
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
public class DoubleLink<T> implements Iterable<T> {
//创建一个双链表类型的结点匿名内部类
private class Node {
//数据域,存放T类型的数据
T data;
//地址域prev->前驱结点,next->后继结点
Node prev, next;
//构造方法重载
public Node(T data, Node prev, Node next) {
this.data = data;
this.prev = prev;
this.next = next;
}
}
//声明头结点
private Node head;
//声明尾结点
private Node rear;
//记录链表长度
private int L;
//构建循环空链表
public DoubleLink() {
//使头结点的3个域均为null
this.head = new Node(null, null, null);
this.rear = null;
this.L = 0;
}
//构造isEmpty()判断链表是否为空
public boolean isEmpty() {
return L == 0;
}
//构造length()方法获取链表长度
public