首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-12-21 
jdk6标准类库源码解读 之 数据结构 (二) LinkedListELinkedListE??此对象使用双向循环链表的方式进行。

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;    }

?

热点排行