container,algorith,iterate
\
http://morningspace.51.net/resource/stlintro/stlintro.html
标准容器
C++标准容器分为序列容器和关联容器,对于序列容器,C++提供的基本序列有
vector 支持随机访问,不适合做插入和删除操作频繁的场景
list 双向链表,适合做元素的插入和删除,不是随机访问
deque 也是一个双端序列,但是经过优化,其双端操作效率类似list,随即访问效率接近vector。
从它们出发,通过定义适当的借口,生成了
stack 默认用deque实现
queue 默认是deque实现
priority_queue 默认是vector保存元素,实现最可能是heap
对于关联容器,C++提供的有:
map 映射
mulitimap 多重映射,相比map,允许重复的key
set 被看做是一个map,其中的值是无关紧要的
mulitiset 相比set,允许重复的key
bitset 位集合
hash_map 散列映射,通过实现一个散列函数,将容器实现为一个散列表,以减少查找元素所需要的时间
标准容器具体用法可以参考C++在线手册STL容器:http://www.cplusplus.com/reference/stl/
Standard library[edit]
The C++ standard consists of two parts: the core language and the C++ Standard Library. C++ programmers expect the latter on every major implementation of C++; it includes vectors, lists, maps, algorithms (find, for_each, binary_search, random_shuffle, etc.), sets, queues, stacks, arrays, tuples, input/output facilities (iostream, for reading from and writing to the console and files), smart pointers for automatic memory management, regular expression support, multi-threading library, atomics support (allowing a variable to be read or written to by at most one thread at a time without any external synchronisation), time utilities (measurement, getting current time, etc.), a system for converting error reporting that doesn't use C++ exceptions into C++ exceptions, a random number generator and a slightly modified version of the C standard library (to make it comply with the C++ type system).
A large part of the C++ library is based on the Standard Template Library (STL). Useful tools provided by the STL include containers as the collections of objects (such as vectors and lists), iterators that provide array-like access to containers, and algorithms that perform operations such as searching and sorting.
Furthermore, (multi)maps (associative arrays) and (multi)sets are provided, all of which export compatible interfaces. Therefore, using templates it is possible to write generic algorithms that work with any container or on any sequence defined by iterators. As in C, the features of the libraryare accessed by using the #include directive to include a standard header. C++ provides 105 standard headers, of which 27 are deprecated.
The standard incorporates the STL that was originally designed by Alexander Stepanov, who experimented with generic algorithms and containers for many years. When he started with C++, he finally found a language where it was possible to create generic algorithms (e.g., STL sort) that perform even better than, for example, the C standard library qsort, thanks to C++ features like using inlining and compile-time binding instead of function pointers. The standard does not refer to it as "STL", as it is merely a part of the standard library, but the term is still widely used to distinguish it from the rest of the standard library (input/output streams, internationalization, diagnostics, the C library subset, etc.).[50]
Most C++ compilers, and all major ones, provide a standards conforming implementation of the C++ standard library.
算法和函数对象
容器本身之所以有用,是因为容器提供了一些基本操作,如确定大小,迭代,复制,排序,查找等。标准库提供了许多算法,服务于容器用户的最普遍和最基本的需要。
标准库算法不过就是60个,每个算法都描述为一个模板函数或一组模板函数,例如最常用的排序算法:sort,能以很好的平均效率排序,建议排序都用sort替换C语言的qsort,sort可以更好结合容器。
标准库算法和函数对象的教程可以参考C++之父的C++程序设计语言的算法和函数对象,这一章内容可以教你如何使用标准库算法和函数对象。
标准库算法的声明在<algorithm>,函数对象在<functional>里。
标准库算法具体用法参考C++在线手册STL算法:http://www.cplusplus.com/reference/algorithm/
迭代器和分配器
迭代器是连接容器和算法的纽带,让写算法的人不必关心各种数据结构的具体细节,而分配器提供了一个映射,将低级的字节形式的数据模型映射到高级的对象模型。
迭代器是每个程序员都需要关心的概念之一,但是分配器仅仅是一个支持机制,标准库已经提供了默认的分配器,很少有程序员需要去写新的分配器。
迭代器在接触STL容器就会了解了,一般迭代器分为正向迭代器,反向迭代器,插入迭代器,带检查的迭代器。
至于分配器提供了一套分配和释放存储的标准方式,标准库提供了一个标准分配器,在<memory>里的标准allocator模板用operator new()分配存储,所有的标准容器在默认情况下使用它,当然你也可以自己实现一个分配器,容器的实现需要一次次的allocate()或者deallocate()对象,意味着new的大量调用,你可以采用一个固定大小存储块的存储池,可以比常规的更通用的operator new()的效率高一些。
container,algorith,iterate的更多相关文章
- Hiero中versionscanner模块结构图
花了两周读这个模块,终于把结构理清楚了,当然新功能也搞定了,搜索条件更宽松,可以找到binitem对象中更多的版本,截图如下: 当然功能也做出来啦: 代码如下: ################### ...
- golang中container/list包源码分析
golang源码包中container/list实际上是一个双向链表 提供链表的一些基本操作,下面就结合定义和接口进行下说明 1. 定义 // Element is an element of a l ...
- 在docker中运行ASP.NET Core Web API应用程序(附AWS Windows Server 2016 widt Container实战案例)
环境准备 1.亚马逊EC2 Windows Server 2016 with Container 2.Visual Studio 2015 Enterprise(Profresianal要装Updat ...
- .Container与.container_fluid区别
.Container与.container_fluid是bootstrap中的两种不同类型的外层容器,两者的区别是:.container 类用于固定宽度并支持响应式布局的容器..container-f ...
- View and Data API Tips: Constrain Viewer Within a div Container
By Daniel Du When working with View and Data API, you probably want to contain viewer into a <div ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- iBatis.net 循环iterate,没有foreach
3.9.4. Iterate Element This tag will iterate over a collection and repeat the body content for each ...
- Docker - command in docker container
1.查看Container 里面运行的进程 在运行容器以后,可以查看里面的进程: docker top <container_id> or <container_name> 2 ...
随机推荐
- 0059 Spring MVC与浏览器间的JSON数据转换--@RequestBody--@ResponseBody--MappingJacson2HttpMessageConverter
浏览器与服务器之间的数据交换有很多类型,不只是表单提交数据这一种,比如ajax技术就大量使用json.xml等,这时候就涉及到浏览器端和服务器端数据格式转换的问题,服务器端都是Java对象,需要把请求 ...
- C++虚函数解析(转载)
虚函数详解第一篇:对象内存模型浅析 C++中的虚函数的内部实现机制到底是怎样的呢? 鉴于涉及到的内容有点多,我将分三篇文章来介绍. 第一篇:对象内存模型浅析,这里我将对对象的内存模型进 ...
- web.config中的connectionString里面应该怎么写?
2009-09-16 10:19信欣玛利 | 浏览 6068 次 网络 就是具体格式.. 谁能举个例子? asp.net 3.5的. 2009-09-16 10:40 提问者采纳 这是用来连 ...
- 74HC164dD驱动LED
驱动要点: 1.上升沿写入串行数据: CLK=0; DAT=num&0x01; CLK=1; 2.写入数据的数码管编码(指代码中的 tab[]) 串行数据是FIFO先进先出,也就是先写高位,移 ...
- hive中关键字作为列名的方法
hive中有很多关键字,直接作为列名,会出错的 例如 下面 user就是关键字,作为字段时报以下错误. 解决方案: 使用·· (ESC下面的那个键,点号)两个符号包裹即可.
- 概率论 - BZOJ - 4001 TJOI2015
TJOI2015 Problem's Link ---------------------------------------------------------------------------- ...
- CI框架中 类名不能以方法名相同
昨天晚上一个坑爹的问题折腾了我一晚上,首先我来说下我的代码,我建立了一个index的控制器然后呢 在控制器里有一个index的方法.页面模板都有. if ( ! defined('BASEPATH' ...
- SSIS 自测题-控制流控件类
说明:以下是自己的理解答案,不是标准的答案,如有不妥烦请指出. 有些题目暂时没有答案,有知道的请留言,互相学习,一起进步. 62.描述一下 Execute SQL Task 的作用,在 ...
- erlang-sunface的博客地址
erlang-sunface的博客地址: http://blog.csdn.net/abv123456789/article/category/2206185
- XAMPP phpmyadmin修改mysql密码
我手动修改了mysql的root账户的密码,然后就访问不了phpmyadmin了. 解决方法: 打开xampp目录(默认的安装目录,如果修改,请找到xampp的安装目录),打开phpmyadmin的目 ...