首页 技术 正文
技术 2022年11月20日
0 收藏 841 点赞 3,478 浏览 1166 个字

<algorithm>是所有STL头文件中最大的一个,其中常用到的功能范围涉及到比较、交换、查找、遍历操作、复制、修改、反转、排序、合并等等。

<numeric>体积很小,只包括几个在序列上面进行简单数学运算的模板函数,包括假发和惩罚在序列上的一些操作。

<functional>中则定义了一些模板类用以声明函数对象。

STL提供了大量实现算法的函数模板,只要我们熟悉了STL之后,许多代码可以被大大的化简,只需要通过调用一两个算法模板,就可以完成所需要的功能,从而大大地提升效率。

adjacent_find();在迭代器对标识元素范围内查找一堆相邻重复元素,找到则返回指向这对元素的第一个元素的迭代器。否则返回past-the-end。

例如:vecInt使用vector<int>声明的容器,现已包含1,2,2,4,5

it = adjacent_find(vecInt.begin(),vecInt.end());

此时*it == 2;

binary_search:在有序的序列中

查找value,找到则返回true,不可在无序序列中使用

 bool bfound = binary_search(setInt.begin(),setInt.end(),);

count:利用等于操作符,把标志范围内的元素与输入值比较,返回相等的个数

 int nCount = count(vecInt.begin(),vecInt.end(),elem);

count_if:利用输入函数,对标志范围内的元素进行比较操作,返回结果为true的个数

merge:合并两个容器

merge(vecIntA.begin(),vecIntA.end(),vecIntB.begin(),vecIntB.end(),vecIntC.begin());

sort:排序(默认升序)

sort(vecInt.begin(),vecInt.end());

random_shuffle:随即洗一次数据

random_shuffle(vecInt.begin(),vecInt.end());

reverse:倒序

reverse(vecInt.begin(),vecInt.end());

copy:拷贝复制函数

copy(vecIntA.begin(),vecIntA.end(),vecIntB.begin());

replase:

replace(vecIntA.begin(),vecIntA.end(),,));//3替换成8,其中3可以是函数满足条件的被替换

accumulate:求和

fill:填充某个数值

set_union:重复的部分没有进去

set_intersection:交集

set_difference:差集

for_each:回调函数去执行每一个元素

transform:调用之后改变自身值并写回到指定容器

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289