jay gamel
0
Q:

iterate through unordered_map c++ in reverse order

// C++ program makes a map to iterate 
// elements in reverse order with simpler 
// syntax 
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    // Creating & Initializing a map of String & Ints 
    map<int, string> mymap; 
  
    // Inserting the elements one by one 
    mymap.insert(make_pair(10, "geeks")); 
    mymap.insert(make_pair(20, "practice")); 
    mymap.insert(make_pair(5, "contribute")); 
  
    // rbegin() returns to the last value of map 
    for (auto it = mymap.rbegin(); it != mymap.rend(); it++) { 
        cout << "(" << it->first << ", " 
             << it->second << ")" << endl; 
    } 
  
    return 0; 
} 
-2

New to Communities?

Join the community