zoukankan      html  css  js  c++  java
  • map 取最大value

    map 取最大value

    源码:

    /*
     * =====================================================================================
     *
     *       Filename:  max.cc
     *
     *    Description:  
     *
     *        Version:  1.0
     *        Created:  04/09/2012 12:57:56 PM
     *       Revision:  none
     *       Compiler:  gcc
     *
     *         Author:  kangle.wang (mn), wangkangluo1@gmail.com
     *        Company:  APE-TECH
     *
     * =====================================================================================
     */
    
    #include <iostream>
    #include <map>
    
    #include <algorithm>
    using namespace std;
    
    template<class T>
    bool pairCompare(const T & x, const T & y)
    {
      return x.second < y.second;
    }
    
    template<class T>
    typename T::const_iterator map_max_element(const T &A)
    {
        typedef typename T::value_type pair_type;
        return max_element(A.begin(), A.end(), pairCompare<typename T::value_type>);
    }
    
    int main()
    {
        map<float, int> A;
        map<float, int>::const_iterator it;
        // Data insert
    
        A.insert ( pair<float, int>( -2, 1) );
        A.insert ( pair<float, int>( 0, 5) );
        A.insert ( pair<float, int>( 2, -5) );
    
        it = map_max_element(A);
    
        cout << "Row with maximum second element of a Map: " << (*it).first << " , " << (*it).second << endl;
    
        return 0;
    }

  • 相关阅读:
    F系列车牌识别设备
    金蝶云星空安装及卸载教程
    RG-RAC256高性能无线控制器
    关于IP网段划分
    Win10关闭自动更新的三种方法
    锐捷网络RG-S2528G-24P
    光纤信号的传输距离
    POE交换机
    光纤收发器
    大华工具管家 1.01.1官方版
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2451086.html
Copyright © 2011-2022 走看看