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. shiro的使用详解~

    在家无聊复习一下shiro 打开了之前的项目,由于lombok插件安装不了,不知道idea抽什么风所以get,set方法报错了,将就一下 只看shiro的使用,配置在shiro分类中有 登录方法 pa ...

  2. 小程序util.js的使用

    我们通过开发者工具快速创建了一个 QuickStart 项目.你可以留意到这个项目里边生成了一个utils/util.js这里写图片描述 可以将一些公共的代码抽离成为一个单独的 js (utils.j ...

  3. MySQL/MariaDB随笔一

    1.yum 安装后先跑一下系统自带的安全脚本,否则数据库很不安全,任何人都可以登录 [root@xixi ~]# mysql_secure_installation NOTE: RUNNING ALL ...

  4. 【JavaScript数据结构系列】00-开篇

    [JavaScript数据结构系列]00-开篇 码路工人 CoderMonkey 转载请注明作者与出处 ## 0. 开篇[JavaScript数据结构与算法] 大的计划,写以下两部分: 1[JavaS ...

  5. lunix如何查看防火墙是否关闭和关闭开启防火墙命令

    查看防火墙是否关闭的命令如下: 1.通过 /etc/init.d/iptables status 或者 service iptables status命令 2.通过 iptables -L命令 查看 ...

  6. cors跨越深度刨析

    解决跨域的方式JSOP,和CORS JSONP不做介绍了. CORS跨域: 参考阮一峰http://www.ruanyifeng.com/blog/2016/04/cors.html 官方:https ...

  7. 关于使用npm成功安装命令后,执行时却报找不到命令的问题

    # 使用npm安装newman命令 ~$ npm install newman --global ... /root/node-v6.9.1-linux-x64/bin/newman -> /r ...

  8. 副业收入是我做程序媛的3倍,工作外的B面人生

    到“程序员”,多数人脑海里首先想到的大约是:为人木讷.薪水超高.工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是 ...

  9. Rocket - debug - TLDebugModuleInner - Abstract Command State Machine

    https://mp.weixin.qq.com/s/RcXI8uEHvZHGCvX3DoVR4Q 简单介绍TLDebugModuleInner中处理抽象命令时的状态机. 1. CtrlState 定 ...

  10. jchdl - GSL实例 - Assign

    https://mp.weixin.qq.com/s/MtHR3iolPd5VQq6AUE-JPg   Assign是一个节点,把输入线直接赋值给输出线.在转换成Verilog时,这种类型的节点会直接 ...