什么是容器?

我们来看看关于标准容器的定义:

standard Containers(标准容器)
A container is a holder object that stores a collection of other objects (its elements).
(容器是一个持有者对象,用于存储一系列称为容器自身元素的其他对象)。
They are implemented as class templates, which allows a great flexibility in the types supported as elements.容器通过类模板实现,这种方式使得容器所支持的元素类型更加灵活多样。
The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators (reference objects with similar properties to pointers).容器不仅为容器的元素提供存储空间的管理,也为容器的元素通过直接访问、迭代器(与指针类似相似性质)访问、成员函数来访问这些元素。

简而言之,容器就是预置的数据结构,但是单一的数据结构是毫无意义的吗,仅仅只是一具不能移动的驱壳,通过算法,使得这具驱壳得到移动,根据现实的需求,我们就可以赋予它们意义。
事实上,容器主要分为两大类:序列容器sequence container,关联容器associative container。

序列容器: vector 向量容器、list 列表容器、deque 双端队列容器。,是因为元素在容器中的位置同元素的值无关,即容器不是排序的。将元素插入容器时,指定在什么位置,元素就会位于什么位置。 按照进入容器的先后顺序进行处理。所以称为序列容器。

序列容器类模板
array(c11)Array class (class template )
vectorVector (class template )
dequeDouble ended queue (class template )
forward_list(c11)Forward list (class template )
listList (class template )

容器适配器
Container adaptors are not full container classes, but classes that provide a specific interface relying on an object of one of the container classes (such as deque or list) to handle the elements. 容器适配器并不完全满足容器类的定义,而是依赖于现有的deque或者list的对象所提供的借口来处理这些元素。
The underlying container is encapsulated in such a way that its elements are accessed by the members of the container adaptor independently of the underlying container class used.
容器根据这样的方式被封装,这些元素可以通过容器成员函数的适配器独立于背后所使用的的容器进行访问。

容器适配器类模板
stackLIFO stack (class template )
queueFIFO queue (class template )
priority_queuePriority queue (class template )

关联容器: 关联容器主要分为两类,一类是有序关联容器,容器内部元素是排好序的,另一类是无序关联容器。关联类容器从结构上可以分为:底层由红黑树实现的set类型分别有set、multiset、unordered_set、unordered_multimap、底层由哈希表实现的map类型分别有map、multimap、unordered_map、unordered_multimap、

有序关联容器类模板
setSet
multisetMultiple-key set
mapmultimap
无序关联容器类模板
unordered_setUnordered Set
unordered_multisetUnordered Multiset
unordered_mapUnordered Map
unordered_multimapUnordered Multimap
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃瓜太狼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值