- 1、本文档共50页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
制作者 : 黄襄念
西华大学数学与计算机学院
2014.01;第六章 非可变序列算法;算法、容器、迭代器、函数对象之关系图;MSDN
The STL algorithms are generic because they can operate on a variety of data structures. The data structures that they can operate on include not only the STL container classes such as vector and list, but also program-defined data structures and arrays of elements that satisfy the requirements of a particular algorithm. STL algorithms achieve this level of generality by accessing and traversing the elements of a container indirectly through iterators.
The STL algorithms extend the actions supported by the operations and member functions of each STL container and allow working, for example, with different types of container objects at the same time. ;算法和容器成员函数的区别
算法:函数模板,不是容器(类模板)的成员函数
—— 直接使用,不是通过容器对象调用
算法:有些与容器的成员函数同名且功能相同
—— 用法不同
头文件
算法: algorithm
数值算法:numeric
函数对象:functional;STL 算法分类
非可变序列算法 算法不修改容器元素的值或顺序
for_each、线性查找、子序列匹配、元素个数、元素比较、最大与最小值
可变序列算法 算法要修改容器元素的值或顺序
复制、填充、交换、变换、替换、生成、删除、反转、唯一、环移、分区、搬移、随机重排。
排序相关算法
排序、折半查找、归并排序、有序集操作、堆排序
数值算法
复数运算、向量运算(值数组valarray)、通用数值计算(求和、内积、部分和、序列相邻差);非可变序列算法;迭代器语义分类;Input 能力弱
单步向前读取元素
单步:自增 iter++ 或 ++iter,错:iter+1
向前:不能反向。错:iter --,iter-1
读取:不能写入迭代器所指元素。
对:… = *iter,错:*iter = …
迭代器赋值与比较
iter1= iter2
= = != ==
STL 预定义迭代器
istream 迭代器;Output 能力弱
单步向前写入元素。类似 Input,区别在于:
Output:只能写 *iter =…,不能读…= *iter
STL预定义迭代器:ostream迭代器, inserter迭代器
Forward 能力弱
单步向前读写元素。Input 和 Output 的结合。
Bidirectional 能力较强
单步双向读写元素。在Forward基础上增加:自减--
支持所有的容器迭代器。
Random 能力强
随机读写元素,在Bidirectional基础上增加:
iter + i, iter – i, iter[i], iter.at(i)
支持容器迭代器:vector, deque, string, array
;MSDN
The template class is an iterator adaptor that describes a reverse iterator object that behaves like a random-access or bidirectional iterator, only in reverse. It enables the backward traversal of a range.
template class RandomIterator
class reverse_iterator
{ … } // 所有标准容器都支持 rbegin(), rend()
(const_)reverse_iterator rbegin()
(const
您可能关注的文档
- 第5章沉淀技术.ppt
- CELL 改造完成报告会资料.ppt
- TKI耐药以后后续治疗.ppt
- B细胞介导体液免疫应答机制.ppt
- CET-4翻译测试中不同水平受试表现有何差异--基于受试答题过程.pptx
- 第5章 电动机电器控制及机床电器控制.ppt
- 第十三章 B淋巴细胞活化与抗体产生.ppt
- CFT的基本概述探索.ppt
- 程序性细胞死亡与细胞的衰老.ppt
- 数学教育研究中存在若干问题.ppt
- 2024年中国钽材市场调查研究报告.docx
- 2024年中国不锈钢清洗车市场调查研究报告.docx
- 2024年中国分类垃圾箱市场调查研究报告.docx
- 2024年中国水气电磁阀市场调查研究报告.docx
- 2024年中国绿藻片市场调查研究报告.docx
- 2010-2023历年初中毕业升学考试(青海西宁卷)数学(带解析).docx
- 2010-2023历年福建厦门高一下学期质量检测地理卷.docx
- 2010-2023历年初中数学单元提优测试卷公式法(带解析).docx
- 2010-2023历年初中毕业升学考试(山东德州卷)化学(带解析).docx
- 2010-2023历年初中毕业升学考试(四川省泸州卷)化学(带解析).docx
文档评论(0)