ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

什么是容器?

2021-09-22 22:07:20  阅读:166  来源: 互联网

标签:容器 container 什么 元素 list template class


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

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

标签:容器,container,什么,元素,list,template,class
来源: https://blog.csdn.net/qq_41722524/article/details/120328754

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有