#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

//二元谓词
//比较两个数的大小
bool absLess(int elementParam1,int elementParam2)
{
  return abs(elementParam1) < abs(elementParam2);
}

int main()
{
  deque<int> deque1;
  for (int k=0;k<10;k++)
  {
    deque1.insert(deque1.end(),k);
  }

  for (int k = -4; k<6; k++)
  {
    deque1.insert(deque1.end(), k);
  }

  deque<int>::iterator deque_iter;
  for (deque_iter = deque1.begin();deque_iter != deque1.end();++deque_iter)
  {
    cout << *deque_iter << " ";
  }
  cout << endl;

  //
  deque<int>::iterator min_index = min_element(deque1.begin(), deque1.end());
  cout << *min_index << endl;

  int min_value = *min_element(deque1.begin(), deque1.end());
  cout << min_value << endl;

  deque<int>::iterator max_index = max_element(deque1.begin(),deque1.end());
  cout << "max:" << *max_index << endl;

  bool b1 = absLess(*min_index,*max_index);
  cout << b1 << endl;

  //绝对最小值
  deque<int>::iterator min_index2 = min_element(deque1.begin(),deque1.end(),absLess);
  cout << "绝对最小值:" << abs(*min_index2) << endl;

  //绝对最大值
  deque<int>::iterator max_index2 = max_element(deque1.begin(),deque1.end(), absLess);
  cout << "绝对最大值:" << abs(*max_index2) << endl;

  system("pause");
  return 0;
}

============================

0 1 2 3 4 5 6 7 8 9 -4 -3 -2 -1 0 1 2 3 4 5
-4
-4
max:9
1
绝对最小值:0
绝对最大值:9
请按任意键继续. . .

c++ STL 最大值最小值的更多相关文章

  1. C# 求链表 list 中 属性的 最大值 最小值

    获取链表List中对象属性最大值最小值(Max,Min)的方法: 1.创建一个类,类中有一个属性A /// <summary> /// 用于测试属性的类 /// </summary& ...

  2. js求最大值最小值

    比较数组中数值的大小是比较常见的操作,比较大小的方法有多种,比如可以使用自带的sort()函数,代码如下: <html> <head> <meta charset=&qu ...

  3. Tunnel Warfare (区间合并|最大值最小值巧妙方法)

    Tunnel Warfare http://acm.hdu.edu.cn/showproblem.php?pid=1540 Time Limit: 4000/2000 MS (Java/Others) ...

  4. java8 stream取出 最大值/最小值

    注:转载请注明出处!!! 这里直接用取出多个对象中某个值 最大/最小 来进行举例 直接看代码 /** * 时间测试类 */ class TimeTest { private Date time; pu ...

  5. html标签内部简单加js 一维数组求最大值 最小值两个值位置和数字金字塔图形

     html标签内部,简单加js <a href=""></a><!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...

  6. C++数组或vector求最大值最小值

    可以用max_element()及min_element()函数,二者返回的都是迭代器或指针. 头文件:#include<algorithm> 1.求数组的最大值或最小值 1)vector ...

  7. php三目运算计算三个数最大值最小值

    文章地址:https://www.cnblogs.com/sandraryan/ $x = 10; $y = 45; $z = 3; //求出三个数字中最大值最小值 //先比较x y,如果x> ...

  8. 使用Java Stream,提取集合中的某一列/按条件过滤集合/求和/最大值/最小值/平均值

    不得不说,使用Java Stream操作集合实在是太好用了,不过最近在观察生产环境错误日志时,发现偶尔会出现以下2个异常: java.lang.NullPointerException java.ut ...

  9. js中快速获取数组中的最大值最小值

    var a=[1,2,3,5]; alert(Math.max.apply(null, a));//最大值 alert(Math.min.apply(null, a)); //最小值 多维数组如下 v ...

随机推荐

  1. How to resolve the 403 error when send POST request from Postman

    Root cause: the site refused the connection from the http request origin, by default it is setted as ...

  2. Octave(1)

    size(A)返回矩阵A的大小: >> A=[ ; ; ]; >> size(A) %返回矩阵A 的大小 ans = >> size(A,) %返回A的第一维度大小 ...

  3. lvs原理及安装部署详解(参考)

    LVS安装使用详解 摘至:http://www.cnblogs.com/MacoLee/p/5856858.html 简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟 ...

  4. java学习笔记16-抽象类

    抽象类: 定义了一系列的属性和方法的类.抽象方法是不能直接实现功能.需要通过继承去实现具体方法.为了将静态的业务流程跟动态的实现分开. 工厂生产产品时,都需要准备材料,执行组装,产品销售等流程.但是对 ...

  5. Python命令行创建虚拟环境

    Python命令行创建虚拟环境 安装virtualenv 启动命令行,执行命令pip install -U virtualenv 创建一个新的虚拟环境 执行命令python -m virtualenv ...

  6. windows下mysql5.6.x的日志正确配置方法(my.ini) (网上的都是5.6之前的版本)

    https://blog.csdn.net/databatman/article/details/49951853 感谢楼主,找了好久,试了一下楼主的,果然是对的,网上的日志配置都是5.6之前的版本: ...

  7. Ubuntu 搭建 Ftp 服务器

    1.在 ubuntu 中 下载 vsftpd  要是你安装了 vsftpd  输入:vsftpd -v ,会有版本提示 如果没有,则进行安装 vsftpd 输入  apt-get install vs ...

  8. 关键字local、global和内置函数【locals、globals】

    每个函数都有着自已的命名空间,叫做局部名字空间,它记录了函数的变量,包括函数的参数和局部定义的变量.每个模块拥有它自已的命名空间,叫做全局命名空间,它记录了模块的变量,包括函数.类.其它导入的模块.模 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description: You play your favourite game yet another time. You chose the character you didn ...

  10. Oracle 物理结构(六) 文件-数据文件

    Oracle 物理结构(六) 文件-数据文件