fork download
  1. // set::key_comp
  2. #include <iostream>
  3. #include <set>
  4. #include <map>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main ()
  10. {
  11. std::set<int> myset;
  12. int highest1, highest2, highest3;
  13. typedef map<int, int> MyMap;
  14. MyMap mymap;
  15.  
  16. std::set<int>::key_compare myCompKeyForSet = myset.key_comp();
  17. std::set<int>::value_compare myCompValForSet = myset.value_comp();
  18.  
  19. MyMap::key_compare myCompKeyForMap = mymap.key_comp();
  20. MyMap::value_compare myCompValForMap = mymap.value_comp();
  21.  
  22.  
  23. for (int i=0; i<=5; i++) {
  24. myset.insert(i);
  25. mymap.insert(make_pair(i, 2*i));
  26. }
  27.  
  28. //////SET///////
  29.  
  30. highest1=*myset.rbegin();
  31. std::set<int>::iterator it=myset.begin();
  32. while ( myCompKeyForSet(*it, highest1) ) it++;
  33. std::cout << "\nhighest1 is " << highest1;
  34.  
  35.  
  36. highest2 = *myset.rbegin();
  37. it=myset.begin();
  38. while ( myCompValForSet(*it, highest2) ) it++;
  39. std::cout << "\nhighest2 is " << highest2;
  40.  
  41. //////MAP///////
  42.  
  43. MyMap::iterator it2 = mymap.begin();
  44. highest3 = mymap.rbegin()->first;
  45. while ( myCompKeyForMap((it2->first), highest3) ) it2++;
  46. std::cout << "\nhighest3 is " << highest3;
  47.  
  48. std::pair<int,int> highest4 = *mymap.rbegin();
  49. it2 = mymap.begin();
  50. while ( myCompValForMap(*(it2), highest4) ) it2++;
  51. std::cout << "\nhighest4 is " << highest4.second;
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
highest1 is 5
highest2 is 5
highest3 is 5
highest4 is 10