什么是容器?

2021/9/22 23:17:49

本文主要是介绍什么是容器?,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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

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


这篇关于什么是容器?的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程