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. VUE 关键字

    转 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...

  2. 剑指Offer之矩形覆盖

    题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 比如n=3时,2*3的矩形块有3种覆盖方法: 思路:与裴波拉 ...

  3. [Office#PPT]0001.实例剖析-如何制作一个牛B的融资PPT

    一些好公司明明在模式上富有创新性,但却在 pitch 时很保守,而且他们又不缺设计和开发能力.如何设计你的融资演讲稿才会吸引投资人对你投资?投资人 Daniel Eckler给大家贡献了下面这篇技术贴 ...

  4. ​云中奈飞(一):Netflix的上云之旅

    作者按: Netflix(译为奈飞/网飞)公司自1997年创立以来,已发展成为美国最大的互联网流媒体服务商.它从2008到2015年间长达七年的将其所有IT系统从自有数据中心迁移到AWS之上的旅程,在 ...

  5. jchdl - RTL实例 - And

    https://mp.weixin.qq.com/s/86d_sFN0xVqk1xRaRyoAkg   使用rtl语法,实现简单的与门.   参考链接 https://github.com/wjcdx ...

  6. IntelliJ IDEA连接不上数据库 (Connection to testdb@localhost failed. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.)

    问题提示为: 原因:MySQL数据库版本为8.0以上,需要在URL加上时区,即加上?serverTimezone=GMT 成功后为:

  7. IDEA字节码学习查看神器jclasslib bytecode viewer介绍

    转载来自:https://blog.csdn.net/w605283073/article/details/103209221 一.背景 很多人想学习Java反汇编后的字节码,但是一方面缺乏好的资料, ...

  8. Nginx 笔记(一)nginx简介与安装

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) Nginx 简介: 1.介绍 nginx 的应用场景和具体可以做什么事情 2.介绍什么是反向代理 3.介 ...

  9. 【Win10】BeyondCompare时提示"许可证密钥已被撤销"的解决办法

    删除...AppData\Roaming\Scooter Software\Beyond Compare 3目录下所有文件. 应该是对应了bcompare的配置文件以及记录文件.删除了之后,就等于新安 ...

  10. Java实现 LeetCode 777 在LR字符串中交换相邻字符(分析题)

    777. 在LR字符串中交换相邻字符 在一个由 'L' , 'R' 和 'X' 三个字符组成的字符串(例如"RXXLRXRXL")中进行移动操作.一次移动操作指用一个"L ...