目录
C++ | STL | 序列容器 | 关联容器
1.前言
2.序列容器
2.1.vector容器
2.2.array容器
2.3.valarray容器
2.4.queue容器
2.5.deque容器
2.6.priority_queue容器
2.7.list容器
2.8.forward_list容器
2.9.bitset容器
2.10.stack容器
2.11.string容器
3.关联容器
3.1.set容器
3.2.multiset容器
3.3.unordered_set容器
3.4.unordered_multiset容器
3.5.map容器
3.6.multimap容器
3.7.unordered_map容器
3.8.unordered_multimap容器
4.参考文献
为什么C++比C更受人欢迎呢?除了C++的编译令人感到更舒适,C++C++的标准模板库(STL)也占了很重要的原因。当你还在用手手写快排、手写二叉堆,挑了半天挑不出毛病的时候,C++党一手STL轻松AC,想不嫉妒都难。
所以这篇随笔就带大家走进博大精深的C++STL,系统讲解各种STL容器及其用法、作用。在学习STL的时候认真体会STL语法及功能,提升自己在算法竞赛及程序设计中解题、码代码的能力。[1]
template < class T, class Alloc = allocator > class vector; // generic template
vector 详解传送门:http://www.cplusplus.com/reference/vector/vector/
动态可随机访问数组,具体参照上面给出的链接,官方解释,一切来辅助资料来源于官网。
template < class T, size_t N > class array;
array 详解传送门:http://www.cplusplus.com/reference/array/array/?kw=array
固定大小的课随机访问的数组,具体参照上面给出的链接。
template class valarray;
valarray 详解传送门:http://www.cplusplus.com/reference/valarray/valarray/?kw=valarray
专门针对数学计算设计的数组,可以容易的执行各种数学操作,具体参照上面给出的链接。
template > class queue;
queue详解传送门:http://www.cplusplus.com/reference/queue/queue/?kw=queue
队列,默认存储容器为deque,具体参照上面给出的链接。
template < class T, class Alloc = allocator > class deque;
deque详解传送门:http://www.cplusplus.com/reference/deque/deque/?kw=deque
双端队列,存储为严格的线性序列,类似vector,注意queue没有这个要求,可使用list等,具体参照上面给出的链接。
template ,
class Compare = less
> class priority_queue;
priority_queue详解传送门:http://www.cplusplus.com/reference/deque/deque/?kw=deque
之前自己也有详细的整理过priority_queue:https://blog.csdn.net/qq_38210354/article/details/107506784
优先队列,内部为堆结构,具体参照上面给出的链接。
template < class T, class Alloc = allocator > class list;
list详解传送门:http://www.cplusplus.com/reference/list/list/?kw=list
双向链表,支持sort 、unique等操作,具体参照上面给出的链接。
template < class T, class Alloc = allocator > class forward_list;
forward_list详解传送门:http://www.cplusplus.com/reference/forward_list/forward_list/?kw=forward_list
单向链表,注意:不支持反向迭代器,支持sort 、unique等操作,具体参照上面给出的链接。
template class bitset;
bitset详解传送门:http://www.cplusplus.com/reference/bitset/bitset/?kw=bitset
位存储容器,专门为二进制位设计,具体参照上面给出的链接。
template > class stack;
stack详解传送门:http://www.cplusplus.com/reference/stack/stack/?kw=stack
栈,具体参照上面给出的链接。
typedef basic_string string;
string详解传送门:http://www.cplusplus.com/reference/string/string/?kw=string
字符串,具体参照上面给出的链接。
template < class T, // set::key_type/value_type
class Compare = less, // set::key_compare/value_compare
class Alloc = allocator // set::allocator_type
> class set;
详解传送门:http://www.cplusplus.com/reference/set/set/?kw=set
内部红黑树实现,不允许关键字重复,内置查找算法,具体参照上面给出的链接。
template < class T, // multiset::key_type/value_type
class Compare = less, // multiset::key_compare/value_compare
class Alloc = allocator > // multiset::allocator_type
> class multiset;
详解传送门:http://www.cplusplus.com/reference/set/multiset/?kw=multiset
内部红黑树实现,允许关键字重复,内置查找算法,具体参照上面给出的链接。
template < class Key, // unordered_set::key_type/value_type
class Hash = hash, // unordered_set::hasher
class Pred = equal_to, // unordered_set::key_equal
class Alloc = allocator // unordered_set::allocator_type
> class unordered_set;
详解传送门:http://www.cplusplus.com/reference/unordered_set/unordered_set/?kw=unordered_set
哈希实现,不像set那样是有序的,unordered_set容器是无序的,具体参照上面给出的链接。
template < class Key, // unordered_multiset::key_type/value_type
class Hash = hash, // unordered_multiset::hasher
class Pred = equal_to, // unordered_multiset::key_equal
class Alloc = allocator // unordered_multiset::allocator_type
> class unordered_multiset;
详解传送门:http://www.cplusplus.com/reference/unordered_set/unordered_multiset/?kw=unordered_multiset
哈希实现,内部无序,允许重复,具体参照上面给出的链接。
template < class Key, // map::key_type
class T, // map::mapped_type
class Compare = less, // map::key_compare
class Alloc = allocator > // map::allocator_type
> class map;
详解传送门:http://www.cplusplus.com/reference/map/map/?kw=map
实现,根据关键字进行排序,可使"[]"进行操作,具体参照上面给出的链接。
template < class Key, // multimap::key_type
class T, // multimap::mapped_type
class Compare = less, // multimap::key_compare
class Alloc = allocator > // multimap::allocator_type
详解传送门:http://www.cplusplus.com/reference/map/multimap/?kw=multimap
红黑树,具体参照上面给出的链接。
template < class Key, // unordered_map::key_type
class T, // unordered_map::mapped_type
class Hash = hash, // unordered_map::hasher
class Pred = equal_to, // unordered_map::key_equal
class Alloc = allocator< pair > // unordered_map::allocator_type
> class unordered_map;
详解传送门:http://www.cplusplus.com/reference/unordered_map/unordered_map/?kw=unordered_map
哈希实现,具体参照上面给出的链接。
template < class Key, // unordered_multimap::key_type
class T, // unordered_multimap::mapped_type
class Hash = hash, // unordered_multimap::hasher
class Pred = equal_to, // unordered_multimap::key_equal
class Alloc = allocator< pair > // unordered_multimap::allocator_type
> class unordered_multimap;
详解传送门:http://www.cplusplus.com/reference/unordered_map/unordered_multimap/?kw=unordered_multimap
哈希实现,具体参照上面给出的链接。
[1]史上最全的C++ STL 容器大礼包:https://www.cnblogs.com/fusiwei/p/11823234.html