Search
 
SCRIPT & CODE EXAMPLE
 

CPP

map in c++ sorted descending order

// C++ program makes a map to store
// elements in descending order
#include <bits/stdc++.h>
using namespace std;
 
// Driver Code
int main()
{
     
    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;
}
Comment

map in c++ sorted descending order

map<key_datatype, value_datatype, greater<int> > mapName;
Comment

PREVIOUS NEXT
Code Example
Cpp :: string to int in c++ 
Cpp :: c++ count number of element in vector 
Cpp :: string vector c++ 
Cpp :: C++ Find the sum of first n Natural Numbers 
Cpp :: how to install boost c++ on windows 
Cpp :: c++ pointer null vs nullptr 
Cpp :: singleton c++ 
Cpp :: how print fload wiht 3 decimal in c++ 
Cpp :: C++ Swap 2 Variables Without Using 3rd Variable 
Cpp :: c++ simple car game 
Cpp :: max heap in c++ 
Cpp :: c++ init multidimensional vector 
Cpp :: primes in range cpp 
Cpp :: prime factorisation of a number in c++ 
Cpp :: c++ greatest common divisor 
Cpp :: how to add an element to std::map 
Cpp :: c++ do while loop 
Cpp :: 1523. Count Odd Numbers in an Interval Range solution in c++ 
Cpp :: how to find 2d vector length cpp 
Cpp :: Count Prefix of a Given String solution leetcode 
Cpp :: function c++ 
Cpp :: how to split string in c++ 
Cpp :: built in function in c++ for binary to decimal 
Cpp :: untitled goose game 
Cpp :: how to square a number in c++ 
Cpp :: Bresenham line drawing opengl cpp 
Cpp :: binary search c++ 
Cpp :: how to initialize vector 
Cpp :: c++ if example 
Cpp :: find in unordered_map c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =