STL map--> sort by value?

Posted by Charlie Epps on Stack Overflow See other posts from Stack Overflow or by Charlie Epps
Published on 2010-04-23T13:50:37Z Indexed on 2010/04/23 13:53 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
|

Hi

I wonder how can I implement the STL map sorting by value.

For example, I have a map m

map<int, int>;
m[1] = 10;
m[2] = 5;
m[4] = 6;
m[6] = 1;

and then.. I'd like to sort that with the m's value. So, if I print the map, I'd like to get the result like

m[6] = 1
m[2] = 5
m[4] = 6
m[1] = 10

this.

How can I sort like this way? Is there any way that I can deal with the key and value with sorted values?

© Stack Overflow or respective owner

Related posts about stl

Related posts about c++