//链表长度 或 结点个数
transient int size = 0;
//头指针
transient Node<E> first;
//尾指针
transient Node<E> last;
//初始化
/**
* Constructs an empty list.
*/
public LinkedList() {
}
//结点类
private static class Node<E> {
E item;
Node<E> next;
Node<E> prev;
Node(Node<E> prev, E element, Node<E> next) {
this.item = element;
this.next = next;
this.prev = prev;
}
}
//添加元素
public boolean add(E e) {
linkLast(e);
return true;
}
//尾插
void linkLast(E e) {
final Node<E> l = last;
final Node<E> newNode = new Node<>(l, e, null);
last = newNode;
if (l == null)
first = newNode;
else
l.next = newNode;
size++;
modCount++;
}