Max value for map

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.