cb27a_c++_STL_算法_最小值和最大值
min_element(b,e) b--begin(), e--end()
min_element(b,e,op). op:函数,函数对象,一元谓词。
max_element(b,e)
max_element(b,e,op)

bool absLess(int elem1, int elem2),返回bool,有两个参数,就是二元谓词

error C2661: “std::deque<int,std::allocator<_Ty>>::insert”: 没有重载函数接受 1 个参数
deque插入需要两个参数。 ideq.insert(ideq.end(),-12);

 /*cb27a_c++_STL_算法_最小值和最大值
min_element(b,e) b--begin(), e--end()
min_element(b,e,op). op:函数,函数对象,一元谓词。
max_element(b,e)
max_element(b,e,op) bool absLess(int elem1, int elem2),返回bool,有两个参数,就是二元谓词 error C2661: “std::deque<int,std::allocator<_Ty>>::insert”: 没有重载函数接受 1 个参数
deque插入需要两个参数。 ideq.insert(ideq.end(),-12);
*/ #include <iostream>
#include <algorithm>
#include <deque>
using namespace std; bool absLess(int elem1, int elem2)
{
return abs(elem1) < abs(elem2);
} int main()
{ deque<int> ideq;
ideq.insert(ideq.end(),-);
for (int i = ; i <= ; ++i)
ideq.insert(ideq.end(), i);
for (int i = -; i <= ; ++i)
ideq.insert(ideq.end(),i);
for (deque<int>::iterator iter = ideq.begin(); iter != ideq.end(); ++iter)
cout << *iter << ' ';
cout << endl;
cout << "min_element返回的是迭代器,所以输出需要解引用" << endl;
cout << "最小值: " << *min_element(ideq.begin(), ideq.end()) << endl; deque<int>::iterator result=min_element(ideq.begin(), ideq.end());
cout << "min_element算法_最小值: " << *result << endl;
cout << "最大值是: " << *max_element(ideq.begin(), ideq.end()) << endl; cout << "绝对最小值: " << *min_element(ideq.begin(), ideq.end(), absLess)<<endl;
cout << "绝对最大值: " << *max_element(ideq.begin(), ideq.end(), absLess) << endl; cout << "绝对最大值abs: " << abs(*max_element(ideq.begin(), ideq.end(), absLess)) << endl;
return ;
}

cb27a_c++_STL_算法_最小值和最大值的更多相关文章

  1. STL_算法_最小值和最大值(min_element、max_element)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) min_element.max_element  找最小.最大值. 非常easy没什么大作用 #include<iost ...

  2. cb51a_c++_STL_算法_根据第n个元素排序nth_element

    cb51a_c++_STL_算法_根据第n个元素排序nth_elementnth_element(b,n,e),比如最大的5个数排序,或者最小的几个数nth_element(b,n,e,p)对比:pa ...

  3. cb50a_c++_STL_算法_局部排序partial_sort

    cb50a_c++_STL_算法_局部排序partial_sort partial_sort(b,se,e)排序一部分,begin,source end,endcout << " ...

  4. cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort

    cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort sort(b,e) sort(b,e,p) stable_sort(b,e) stable_sort(b,e,p) ...

  5. cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition

    cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition random_shuffle()//重排,随机重排,打乱顺序 partition()分区,把 ...

  6. cb47a_c++_STL_算法_排列组合next_prev_permutation

    cb47a_c++_STL_算法_排列组合next_prev_permutation 使用前必须先排序.必须是 1,2,3或者3,2,1.否者结果不准确.如果, 1,2,4,6.这样数据不会准确nex ...

  7. cb46a_c++_STL_算法_逆转和旋转reverse_rotate函数advance

    cb46a_c++_STL_算法_逆转和旋转reverse_rotateSTL算法--变序性算法reverse() 逆转reverse_copy()一边复制一般逆转rotate()旋转,某个位置开始前 ...

  8. cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据

    cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据unique(b,e),删除连续性的,删除重复的数据,比如如果有两个连续的5,5,则留下一个.uniqu ...

  9. cb44a_c++_STL_算法_删除_(2)remove_copy_remove_copy_if

    cb44a_c++_STL_算法_删除_(2)remove_copy_remove_copy_if remove_copy()//在复制过程中删除一些数据remove_copy_if() 删除性算法: ...

随机推荐

  1. java中碰到的异常

    mapper接口中找不到相应方法 解决:配置xml读取路径错误 org.apache.ibatis.binding.BindingException: Invalid bound statement ...

  2. java导入web项目httpservlet报错

    于是开始了,调错之路. 解决方法:鼠标右击项目工程——>Build Path——>点击comfigure Build Path进入----->选择java Bulid Path--- ...

  3. cp: 无法创建普通文件 : 文件已存在

    背景 碰到一个偶现的编译出错问题,如图 报错的信息是 cp: 无法创建普通文件"xxx": 文件已存在 排查原因 看了下 Makefile,这句非常简单,就是 cp ./xxx . ...

  4. Weblogic 漏洞利用总结

    整理的一些利用方式,后续会更新到15年至今的洞 后台爆破拿shell 后台爆破: 部署-安装-上载文件 制作war包,一直下一步,最好保存 jar -cvf shell.war ./shll/* 上传 ...

  5. MyBatis主配置文件

    MyBatis的使用非常简单,使用流程整体可以分成以下四步: public class UserDaoTest { private SqlSessionFactory sqlSessionFactor ...

  6. 使用ansible控制Hadoop服务的启动和停止

    一.环境: 服务器一台,已安装centos7.5系统,做ansible服务器: 客户机三台:hadoop-master(192.168.1.18).hadoop-slave1(192.168.1.19 ...

  7. 【zookeeper】安装教程文档需下载

    请查看文件https://download.csdn.net/download/qq_42158942/11846847 zookeeper的作用 • ZooKeeper 是一个开源的分布式协调服务, ...

  8. JAVASE(十二) Java常用类: 包装类、String类、StringBuffer类、时间日期API、其他类

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 1.包装类 1 .1 八个包装类 ​ 1. 2 基本数据类型,包装类,String者之间的转换 ​ 2. ...

  9. Java实现 蓝桥杯VIP 基础练习 芯片测试

    问题描述 有n(2≤n≤20)块芯片,有好有坏,已知好芯片比坏芯片多. 每个芯片都能用来测试其他芯片.用好芯片测试其他芯片时,能正确给出被测试芯片是好还是坏.而用坏芯片测试其他芯片时,会随机给出好或是 ...

  10. Java实现蓝桥杯模拟正整数序列的数量

    问题描述 小明想知道,满足以下条件的正整数序列的数量: 1. 第一项为 n: 2. 第二项不超过 n: 3. 从第三项开始,每一项小于前两项的差的绝对值. 请计算,对于给定的 n,有多少种满足条件的序 ...