读书人

jdk6基准类库源码解读 之 数据结构 (

发布时间: 2012-12-21 12:03:49 作者: rapoo

jdk6标准类库源码解读 之 数据结构 (二) LinkedList<E>

LinkedList<E>

?

?

此对象使用双向循环链表的方式进行。定义内部对象LinkedList.Entry<E>,用于存储链表中的每个节点,每个节点结构包括前一节点指针、后一节点指针、当前节点值。
?indexOf操作同ArrayList,进行顺序的比较查找。
    public int indexOf(Object o) {        int index = 0;        if (o == null) {            for (Entry e = header.next; e != header; e = e.next) {                if (e.element == null)                    return index;                index++;            }        } else {            for (Entry e = header.next; e != header; e = e.next) {                if (o.equals(e.element))                    return index;                index++;            }        }        return -1;    }

?

读书人网 >编程

热点推荐