zoukankan      html  css  js  c++  java
  • 最大值最小值(max,max_element)

    min

      如果比不出大小就返回第一个引数

    //版本一:调用operator< 
    template <class LessThanComparable>
    const LessThanComparable& min(const LessThanComparable &a,const LessThanComparable& b);
    
    //版本二:调用自己定义的function object来比较
    template <class T,class BinaryPredicate>
    const T& min(const T &a,const T& b,v cmp);

    max

      如果比不出大小就返回第一个引数

    //版本一:调用operator< 
    template <class LessThanComparable>
    const LessThanComparable& max(const LessThanComparable &a,const LessThanComparable& b);
    
    //版本二:调用自己定义的function object来比较
    template <class T,class BinaryPredicate>
    const T& max(const T &a,const T& b,v cmp);

    min_element

      返回range内再有没有其他iterator 指向的值小于*i的iterator i,如果range为空,返回last

    //版本一:调用operator< 
    template <class ForwardIterator>
    ForwardIterator min_element(ForwardIterator first,ForwardIterator last);
    
    //版本二:调用自己定义的function object来比较,返回cmp(*j,*i)为false的i
    template <class ForwardIterator,class BinaryPredicate>
    ForwardIterator min_element(ForwardIterator first,ForwardIterator last,BinaryPredicate cmp);

    max_element

      返回range内再也没有其他iterator所指的值大于*i的iterator i,若为空,返回last

    //版本一:调用operator< 
    template <class ForwardIterator>
    ForwardIterator max_element(ForwardIterator first,ForwardIterator last);
    
    //版本二:调用自己定义的function object来比较,返回cmp(*i,*j)为false的i
    template <class ForwardIterator,class BinaryPredicate>
    ForwardIterator max_element(ForwardIterator first,ForwardIterator last,BinaryPredicate cmp);
  • 相关阅读:
    模拟乒乓球双打和单打比赛
    关于zip内置函数的应用及在 Python 2 和 3 的不同之处
    计算文本平均列数
    四则运算
    Python跳一跳小游戏
    数据库
    类和正则表达
    带进度条的圆周率计算
    球队预测
    自己的第一个网页
  • 原文地址:https://www.cnblogs.com/tianzeng/p/10403569.html
Copyright © 2011-2022 走看看