容器库是一组支持常用的数据结构的泛型类/算法函数库,包含队列,链表,栈等。容器分三种类型:顺序容器,关联容器和无序关联容器,各自支持相应的一组操作。
容器自动管理存储空间,并提供访问单个元素的函数。这种访问可以是直接访问,也可以是通过迭代器(类似指针的对象)进行访问。
大部分容器类都拥有一些功能相同的成员函数。具体选择时,需要考虑容器所提供的功能,以及在特定工作场合下的效率。
[编辑] 顺序容器
顺序容器是提供能够按顺序访问元素功能的容器。
[编辑] 关联容器
关联容器通过使用已排序的数据结构,提供O(log n)时间复杂度的快速搜索。
[编辑] 无序关联容器
无序关联容器是提供基于哈希(Hash)表进行平均O(1)时间复杂度,最坏O{n}时间复杂度搜索功能的容器。
[编辑] 容器适配器
容器适配器提供顺序容器的特殊接口。
[编辑] 成员函数表
|
- C++03中出现的函数
|
|
- C++11开始出现的函数
|
|
顺序容器
|
关联容器
|
无序关联容器
|
容器适配器
|
头文件
|
<array>
|
<vector>
|
<deque>
|
<forward_list>
|
<list>
|
<set>
|
<map>
|
<unordered_set>
|
<unordered_map>
|
<stack>
|
<queue>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(隐式)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(隐式)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(implicit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
N/A
|
|
|
|
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
迭代器
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
N/A
|
N/A
|
N/A
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
N/A
|
N/A
|
N/A
|
|
|
|
|
N/A
|
|
|
|
|
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
|
|
|
|
N/A
|
|
|
|
|
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
N/A
|
元素访问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