public class LinkedList<E>
extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, java.io.Serializable
private transient Entry<E> header = new Entry<E>(null, null, null); //队列的头部
public LinkedList() { //默认构造函数 空的队列 只有一个头!
header.next = header.previous = header;
}
LinkedList 使用 private static class Entry<E> {
E element;
Entry<E> next;
Entry<E> previous; 存储元素,双向循环链表
private Entry<E> entry(int index) { 这个函数将给定的位置值 找到具体对应的Entry 为了提高效率 size>>1 返回 整 个队列的中间位置 然后根据index的相对位置来决定从前还是从后找
if (index < 0 || index >= size)
throw new IndexOutOfBoundsException("Index: "+index+
", Size: "+size);
Entry<E> e = header;
if (index < (size >> 1)) {
for (int i = 0; i <= index; i++)
e = e.next;
} else {
for (int i = size; i > index; i--)
e = e.previous;
}
return e;
}
此外 ,LinkedList里面还有两个private class 来充当 Iterator 迭代器
private class DescendingIterator implements Iterator 反向的!
private class ListItr implements ListIterator<E>