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);
  • 相关阅读:
    C#下对象与JSON串互相转换
    靠纯技术是否能渡过中年危机
    个人小结
    Qt:Drag-Drop操作在QGraphicsView及Model/View框架下的实现
    Lex&Yacc Parser错误发生后再次parser之前恢复初始状态
    lex中yyrestart()的使用
    go特性-数组与切片
    go特性-defer
    golang实现mysql udf
    go创建动态库
  • 原文地址:https://www.cnblogs.com/tianzeng/p/10403569.html
Copyright © 2011-2022 走看看