Max value for map
Source code:
/* * ===================================================== ========================================================== ====== ** 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 ;}
End