zoukankan      html  css  js  c++  java
  • STL: max和min

    max

    Compares two objects and returns the larger of the two, where the ordering criterion may be specified by a binary predicate.

    template<class Type>
       const Type& max(
          const Type& _Left, 
          const Type& _Right
       );
    template<class Type, class Pr>
       const Type& max(
          const Type& _Left, 
          const Type& _Right,
          BinaryPredicate _Comp
       );

    min

    Compares two objects and returns the lesser of the two, where the ordering criterion may be specified by a binary predicate.

    template<class Type>
       const Type& min(
          const Type& _Left, 
          const Type& _Right
       );
    template<class Type, class Pr>
       const Type& min(
          const Type& _Left, 
          const Type& _Right,
          BinaryPredicate _Comp
       );

    max和min还可以比较集合的大小。比如:set,multiset,vector,list,queue,stack,map,multimap.因为集合重载了比较操作符。此外,string,非STL标准的hash_set,hash_map都可以。

    minmax

    Compares two input parameters and returns them as a pair, in order of least to greatest.

    template<class Type>
        pair<const Type&, const Type&>
            minmax(
                const Type& _Left,
                const Type& _Right
    );
    template<class Type, class BinaryPredicate>
        pair<const Type&, const Type&>
            minmax(
                const Type& _Left,
                const Type& _Right,
                BinaryPredicate _Comp
    )

    max_element

    Finds the first occurrence of largest element in a specified range where the ordering criterion may be specified by a binary predicate.

    template<class ForwardIterator>
       ForwardIterator max_element(
          ForwardIterator _First, 
          ForwardIterator _Last
       );
    template<class ForwardIterator, class BinaryPredicate>
       ForwardIterator max_element(
          ForwardIterator _First, 
          ForwardIterator _Last, 
          BinaryPredicate _Comp
       );

    min_element

    Finds the first occurrence of smallest element in a specified range where the ordering criterion may be specified by a binary predicate.

    template<class ForwardIterator>
       ForwardIterator min_element(
          ForwardIterator first, 
          ForwardIterator last
       );
    template<class ForwardIterator, class BinaryPredicate>
       ForwardIterator min_element(
          ForwardIterator first, 
          ForwardIterator last,
          BinaryPredicate comp
       );

    minmax_element

    Performs the work performed by min_element and max_element in one call.

    template<class ForwardIterator>
        pair< ForwardIterator, ForwardIterator >
            minmax_element(
                ForwardIterator _First, 
                ForwardIterator _Last
     );
    template<class ForwardIterator, class BinaryPredicate>
        pair< ForwardIterator, ForwardIterator >
            minmax_element(
                ForwardIterator _First, 
                ForwardIterator _Last, 
                BinaryPredicate _Comp
  • 相关阅读:
    root登录出现“sorry, that didn't work please try again”
    【自适应辛普森】积分计算
    【CF1553F】Pairwise Modulo
    调和级数的复杂度
    CF 1600-2000 的思维题
    中超热身赛(2021湘潭全国邀请赛-重现)补题
    牛客2021年度训练联盟热身训练赛第一场(讲题)
    新知识-Queue_循环队列
    新知识-valueOf(Leetcode 1556_千位分隔符)
    新知识-位运算(Leetcode 217_存在重复元素)
  • 原文地址:https://www.cnblogs.com/freewater/p/2947811.html
Copyright © 2011-2022 走看看