Mega Code Archive

 
Categories / C++ / Data Structure
 

Use the greater function object in Map

#include <iostream> #include <map> #include <functional> #include <string> using namespace std; int main() {   map<string, int, greater<string> > mapObject;   mapObject["A"] = 20;   mapObject["B"] = 19;   mapObject["C"] = 10;   map<string, int, greater<string> >::iterator p;      for(p = mapObject.begin(); p != mapObject.end(); p++) {     cout << p->first << " has value of ";     cout << p->second << endl;   }   return 0; }