美文网首页
list 基本复习

list 基本复习

作者: Mattle | 来源:发表于2021-06-28 09:44 被阅读0次

ArrayList:
1:底层是数组结构。支持随机访问。
2:扩容机制:当前数组元素下标到达数组长度时,进行1.5倍扩容。

// 在grow函数中以1.5的速度扩容。
int newCapacity = oldCapacity + (oldCapacity >> 1);

LinkedList:
1:底层是个双端列表。不支持随机访问。增删快。不需要像ArrayList调用System.arraycopy(),实际操作的是node节点。不需要扩容。

2:获取数据:

// 操作对应节点的Item,相对于ArrayList多了一层node的引用。
public E get(int index) {
     this.checkElementIndex(index);
     return this.node(index).item;
}
// 二分查找
LinkedList.Node<E> node(int index) {
        LinkedList.Node x;
        int i;
        if (index < this.size >> 1) {
            x = this.first;
            for(i = 0; i < index; ++i) {
                x = x.next;
            }
            return x;
        } else {
            x = this.last;
            for(i = this.size - 1; i > index; --i) {
                x = x.prev;
            }
            return x;
        }
    }

相关文章

  • list 基本复习

    ArrayList:1:底层是数组结构。支持随机访问。2:扩容机制:当前数组元素下标到达数组长度时,进行1.5倍扩...

  • python 容器类型

    一、复习 1.基本数据类型int、float、bool、complex、str、list、dict、tuple、 ...

  • (3)Try hard | 一个英专生的学习记录

    背诵单词:list4,复习list1,list2 and list3 list4: ballet,balot,ba...

  • 3/11day08_List接口_Set接口_Collectio

    复习 今日内容 List接口List接口的实现类(ArrayList,LinkedList,Vector) Set...

  • list基本操作

    1、轮询 1.1 根据下标轮询 1.2 根据值轮询 2、切片 2.1 代码 3、tuple 和list 相互转化 ...

  • Python之list

    基本用法 cmp(list1,list2) len(list1) max(list1) min(list1) li...

  • 📅笔记

    趣学指南 ? List: 序列的基本操作 let list = [1,2,3]head list -> ...

  • (2)Try hard | 一个英专生的学习记录

    本篇首发于公众号: 学英语的灼灼 更多内容请关注公众号 背诵单词:list3 复习list1 and list2 ...

  • 2019-05-21

    今天复习了一下Python基础。 1. List 和 Tuple List: L = [1,2,3,4,5,6],...

  • 如何上好复习课

    复习课 (一)复习课的任务 1、复习知识 既要注意对基本概念、基本要点、基本规律、基本原理等知识的复习,也要注意对...

网友评论

      本文标题:list 基本复习

      本文链接:https://www.haomeiwen.com/subject/vdakyltx.html