码迷,mamicode.com
首页 > 其他好文 > 详细

集合类 collection接口 LinkedList

时间:2018-01-02 23:20:42      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:pre   添加   font   this   body   bubuko   links   info   last   

LinkedList 是另外一种重要的数据结构形式, 底层是使用了双向链表数据结构, 特点: 查询速度慢,增删快。

继承关系如下:

技术分享图片

可以发现,LinkedList同时实现了Quene和Deque接口。

静态内部类Node的实现:

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

对应的初始化方法即add()添加方法:

    /**
     * Links e as last element.
     */
    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++;
    }

 

集合类 collection接口 LinkedList

标签:pre   添加   font   this   body   bubuko   links   info   last   

原文地址:https://www.cnblogs.com/heapStark/p/8179238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!