标准
STL
序列容器:
vector
、
string
、
deque
和
list
。
标准STL
关联容器:
set
、
multiset
、
map
和
multimap
。
非标准序列容器slist
和
rope
。
slist
是一个单向链表,
rope
本质上是一
“
重型
”string
。
非标准的关联容器hash_set
、
hase_multiset
、
hash_map
和
hash_multimap
。
几种标准的非STL
容器,包括数组、
bitset
、
valarray
、
stack
、
queue
和
priority_queue
。
顺序容器类型 | |
顺序容器 |
|
Vector | 支持快速随机访问 |
List | 支持快速插入 / 删除 |
Deque | 双端队列 |
顺序容器适配器 |
|
Stack | 后进先出( LIFO )栈 |
Queue | 先进后出( FIFO )队列 |
Priority_queue | 有优先级管理的队列 |
关联容器类型 |
|
Map | 关联数组:元素通过键来存储和读取 |
Set | 大小可变的集合,支持通过键实现的快速读取 |
Multimap | 支持同一个键多次出现的 map 类型 |
Multiset | 支持同一个键多次出现的 set 类型 |
标准
STL
序列容器:
vector
、
string
、
deque
和
list
。
标准STL 关联容器: set 、
multiset 、 map 和 multimap 。
非标准序列容器slist 和 rope 。
slist 是一个单向链表, rope 本质上是一 “ 重型 ”string 。
非标准的关联容器hash_set 、
hase_multiset 、 hash_map 和 hash_multimap 。
几种标准的非STL 容器,包括数组、 bitset
、 valarray 、 stack 、 queue 和
priority_queue 。
顺序容器类型 | |
顺序容器 |
|
Vector | 支持快速随机访问 |
List | 支持快速插入 / 删除 |
Deque | 双端队列 |
顺序容器适配器 |
|
Stack | 后进先出( LIFO )栈 |
Queue | 先进后出( FIFO )队列 |
Priority_queue | 有优先级管理的队列 |
关联容器类型 |
|
Map | 关联数组:元素通过键来存储和读取 |
Set | 大小可变的集合,支持通过键实现的快速读取 |
Multimap | 支持同一个键多次出现的 map 类型 |
Multiset | 支持同一个键多次出现的 set 类型 |
std::deque (double-ended queue) is an indexed sequence container that allows fast insertion and deletion at both its beginning and its end.
std::map is a sorted associative container that contains key-value pairs with unique keys implemented by red-black tree,with logarithmic complexity for Search, removal, and insertion operations .
Unordered map is an associative container that contains key-value pairs with (not sorted)unique keys. Search, insertion, and removal of elements have average constant-time complexity.
deque:同上,O(1)
map:双向迭代器,不过由于是关联容器,需要通过key访问alue的方法,O(h),h为树的高度
unordered_map:前向迭代器,同上,平摊复杂度O(1),最差O(n),也与散列函数的好坏有关。
string:同vector