C++ | STL | 序列容器 | 关联容器

C++ | STL | 序列容器 | 关联容器

目录

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.参考文献


1.前言

       为什么C++比C更受人欢迎呢?除了C++的编译令人感到更舒适,C++C++的标准模板库(STL)也占了很重要的原因。当你还在用手手写快排、手写二叉堆,挑了半天挑不出毛病的时候,C++党一手STL轻松AC,想不嫉妒都难。

        所以这篇随笔就带大家走进博大精深的C++STL,系统讲解各种STL容器及其用法、作用。在学习STL的时候认真体会STL语法及功能,提升自己在算法竞赛及程序设计中解题、码代码的能力。[1]

2.序列容器

2.1.vector容器

template < class T, class Alloc = allocator<T> > class vector; // generic template

        vector 详解传送门:http://www.cplusplus.com/reference/vector/vector/

         动态可随机访问数组,具体参照上面给出的链接,官方解释,一切来辅助资料来源于官网。

2.2.array容器

template < class T, size_t N > class array;

        array 详解传送门:http://www.cplusplus.com/reference/array/array/?kw=array

         固定大小的课随机访问的数组,具体参照上面给出的链接。

2.3.valarray容器

template <class T> class valarray;

         valarray 详解传送门:http://www.cplusplus.com/reference/valarray/valarray/?kw=valarray

         专门针对数学计算设计的数组,可以容易的执行各种数学操作,具体参照上面给出的链接。

2.4.queue容器

template <class T, class Container = deque<T> > class queue;

         queue详解传送门:http://www.cplusplus.com/reference/queue/queue/?kw=queue

         队列,默认存储容器为deque,具体参照上面给出的链接。

2.5.deque容器

template < class T, class Alloc = allocator<T> > class deque;

        deque详解传送门:http://www.cplusplus.com/reference/deque/deque/?kw=deque

        双端队列,存储为严格的线性序列,类似vector,注意queue没有这个要求,可使用list等,具体参照上面给出的链接。

2.6.priority_queue容器

template <class T, class Container = vector<T>, 
          class Compare = less<typename Container::value_type> 
          > class priority_queue;

        priority_queue详解传送门:http://www.cplusplus.com/reference/deque/deque/?kw=deque

        之前自己也有详细的整理过priority_queuehttps://blog.csdn.net/qq_38210354/article/details/107506784

        优先队列,内部为堆结构,具体参照上面给出的链接。

2.7.list容器

template < class T, class Alloc = allocator<T> > class list;

         list详解传送门:http://www.cplusplus.com/reference/list/list/?kw=list

         双向链表,支持sort 、unique等操作,具体参照上面给出的链接。

2.8.forward_list容器

template < class T, class Alloc = allocator<T> > class forward_list;

         forward_list详解传送门:http://www.cplusplus.com/reference/forward_list/forward_list/?kw=forward_list

         单向链表,注意:不支持反向迭代器,支持sort 、unique等操作,具体参照上面给出的链接。

2.9.bitset容器

template <size_t N> class bitset;

           bitset详解传送门:http://www.cplusplus.com/reference/bitset/bitset/?kw=bitset

           位存储容器,专门为二进制位设计,具体参照上面给出的链接。

2.10.stack容器

template <class T, class Container = deque<T> > class stack;

           stack详解传送门:http://www.cplusplus.com/reference/stack/stack/?kw=stack

           栈,具体参照上面给出的链接。

2.11.string容器

typedef basic_string<char> string;

          string详解传送门:http://www.cplusplus.com/reference/string/string/?kw=string

          字符串,具体参照上面给出的链接。


3.关联容器

3.1.set容器

template < class T,                        // set::key_type/value_type
           class Compare = less<T>,        // set::key_compare/value_compare
           class Alloc = allocator<T>      // set::allocator_type
           > class set;

          详解传送门:http://www.cplusplus.com/reference/set/set/?kw=set

          内部红黑树实现,不允许关键字重复,内置查找算法,具体参照上面给出的链接。

3.2.multiset容器

template < class T,                        // multiset::key_type/value_type
           class Compare = less<T>,        // multiset::key_compare/value_compare
           class Alloc = allocator<T> >    // multiset::allocator_type
           > class multiset;

          详解传送门:http://www.cplusplus.com/reference/set/multiset/?kw=multiset

          内部红黑树实现,允许关键字重复,内置查找算法,具体参照上面给出的链接。

3.3.unordered_set容器

template < class Key,                        // unordered_set::key_type/value_type
           class Hash = hash<Key>,           // unordered_set::hasher
           class Pred = equal_to<Key>,       // unordered_set::key_equal
           class Alloc = allocator<Key>      // unordered_set::allocator_type
           > class unordered_set;

           详解传送门:http://www.cplusplus.com/reference/unordered_set/unordered_set/?kw=unordered_set

           哈希实现,不像set那样是有序的,unordered_set容器是无序的,具体参照上面给出的链接。

3.4.unordered_multiset容器

template < class Key,                         // unordered_multiset::key_type/value_type
           class Hash = hash<Key>,            // unordered_multiset::hasher
           class Pred = equal_to<Key>,        // unordered_multiset::key_equal
           class Alloc = allocator<Key>       // unordered_multiset::allocator_type
           > class unordered_multiset;

            详解传送门:http://www.cplusplus.com/reference/unordered_set/unordered_multiset/?kw=unordered_multiset

            哈希实现,内部无序,允许重复,具体参照上面给出的链接。

3.5.map容器

template < class Key,                                     // map::key_type
           class T,                                       // map::mapped_type
           class Compare = less<Key>,                     // map::key_compare
           class Alloc = allocator<pair<const Key,T> >    // map::allocator_type
           > class map;

            详解传送门:http://www.cplusplus.com/reference/map/map/?kw=map

            实现,根据关键字进行排序,可使"[]"进行操作,具体参照上面给出的链接。

3.6.multimap容器

template < class Key,                                     // multimap::key_type
           class T,                                       // multimap::mapped_type
           class Compare = less<Key>,                     // multimap::key_compare
           class Alloc = allocator<pair<const Key,T> >    // multimap::allocator_type

            详解传送门:http://www.cplusplus.com/reference/map/multimap/?kw=multimap

            红黑树,具体参照上面给出的链接。

3.7.unordered_map容器

template < class Key,                                    // unordered_map::key_type
           class T,                                      // unordered_map::mapped_type
           class Hash = hash<Key>,                       // unordered_map::hasher
           class Pred = equal_to<Key>,                   // unordered_map::key_equal
           class Alloc = allocator< pair<const Key,T> >  // unordered_map::allocator_type
           > class unordered_map;

          详解传送门:http://www.cplusplus.com/reference/unordered_map/unordered_map/?kw=unordered_map

          哈希实现,具体参照上面给出的链接。

3.8.unordered_multimap容器

template < class Key,                                    // unordered_multimap::key_type
           class T,                                      // unordered_multimap::mapped_type
           class Hash = hash<Key>,                       // unordered_multimap::hasher
           class Pred = equal_to<Key>,                   // unordered_multimap::key_equal
           class Alloc = allocator< pair<const Key,T> >  // unordered_multimap::allocator_type
           > class unordered_multimap;

           详解传送门:http://www.cplusplus.com/reference/unordered_map/unordered_multimap/?kw=unordered_multimap

           哈希实现,具体参照上面给出的链接。


4.参考文献

[1]史上最全的C++ STL 容器大礼包:https://www.cnblogs.com/fusiwei/p/11823234.html

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值