它是一个链表,一个数组?我四处搜寻,只发现有人在猜测.我的C知识不足以查看源代码.
显然;-)标准容器提供某种形式的保证.
什么类型的保证以及不同类型的容器之间究竟有什么区别?
Container Types:
================
Container:
Forward Container
Reverse Container
Random Access Container
Sequence
Front Insert Sequence
Back Insert Sequence
Associative Container
Simple Associative Container
Pair Associative Container
Sorted Associative Container
Multiple Associative Container
Container Types mapped to Standard Containers
=============================================
std::vector: Sequence Back Sequence Forward/Reverse/Random Container
std::deque: Sequence Front/Back Sequence Forward/Reverse/Random Container
std::list: Sequence Front/Back Sequence Forward/Reverse Container
std::set: Sorted/Simple/Unique Associative Container Forward Container
std::map: Sorted/Pair/Unique Associative Container Forward Container
std::multiset: Sorted/Simple/Multiple Associative Container …Run Code Online (Sandbox Code Playgroud) 用于实现Python内置列表数据类型的典型底层数据结构是什么?
今天在课堂上,我们了解到从列表中检索元素是python中的O(1).为什么会这样?假设我有4个项目的列表,即:
li=["perry", 1, 23.5, "s"]
Run Code Online (Sandbox Code Playgroud)
这些项目的内存大小不同.因此不可能获取内存位置li[0],并添加每个元素大小的3倍来获取内存位置li[3].那么解释器如何知道在哪里li[3]而不必遍历列表来搜索它?