Sorting map in C++

Revision en1, by arham___khan, 2021-07-24 07:43:28

If I have a map<string,pair<int,int>> and I want to sort it in three different ways. 1.Sort by key. 2.Sort by value of first element in the pair. 3.Sort by value of second element in the pair.

Example : if mp [ {a,{9,7}} {y,{2,5}} {g,{3,1}} {i,{6,6}} {e,{1,2}} ]

1.Sort by key:
2.Sort by value of first element in the pair:
3.Sort by value of second element in the pair:

How to implement the above-mentioned three ways of sorting?

Tags #std::map, #sorting

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English arham___khan 2021-07-24 07:43:28 740 Initial revision (published)