Noel
0
Q:

map in decreasing order

// C++ program makes a map to store 
// elements in descending order. 
#include<bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    // Here if greater<int> is used to make 
    // sure that elements are stored in 
    // descending order of keys. 
    map<int, string, greater <int> > mymap; 
  
    // Inserting the elements one by one 
    mymap.insert(make_pair(10, "queen")); 
    mymap.insert(make_pair(20, "rose")); 
    mymap.insert(make_pair(5," lion")); 
  
    // begin() returns to the first value of map. 
    map<int,string> :: iterator it; 
    for (it=mymap.begin() ; it!=mymap.end() ; it++) 
        cout << "(" << (*it).first << ", "
             << (*it).second << ")" << endl; 
  
    return 0; 
} 
1

New to Communities?

Join the community