LinkedList

数据结构:

链表

        public LinkedList() {
        this.header = new Entry(null, null, null);
        this.size = 0;

        this.header.next = (this.header.previous = this.header);
    }    

private static class Entry<E> {
E element;
Entry<E> next;
Entry<E> previous;
//元素,上一个,下一个
Entry(E paramE, Entry<E> paramEntry1, Entry<E> paramEntry2) {
this.element = paramE;
this.next = paramEntry1;
this.previous = paramEntry2;
}
}

 

增删改查:

初始化,上一个和下一个都是他本身。

增加:

public boolean add(E paramE) {
addBefore(paramE, this.header);
return true;
}

private Entry<E> addBefore(E paramE, Entry<E> paramEntry) {
Entry localEntry = new Entry(paramE, paramEntry, paramEntry.previous);
localEntry.previous.next = localEntry;
localEntry.next.previous = localEntry;
this.size += 1;
this.modCount += 1;
return localEntry;
}

  

 

posted on 2016-07-23 18:52  petroe  阅读(201)  评论(0编辑  收藏  举报

导航