非可变序列算法与迭代器.pptx

  1. 1、本文档共50页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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

文档评论(0)

beautyeve + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档