# Thread: sorting map by value

1. ## sorting map by value

Hi,

a basic question how do i sort my map by value:

example

Code:
```map<int, int> m;
m[1] = 10;
m[3] = 10;
m[6] = 5;
m[12] = 14;```
what i need is :

Code:
```m[12] = 14;
m[3] = 10;
m[1] = 10;
m[5] = 6;```
so if i have duplicate values then key order should be considered. well i'll figure out the key order latter, for now i would appreciate some basic help with value order. I mean i could first copy the values int a vector and the sort the vector and then reassign key values but that sounds complicated. is there a faster (or at least a simpler ) way to do this. all i need to know is the order of keys give the values are sorted (biggest to smallest)

thnx

2. Perhaps you should map the other way instead, or if you need both, then boost bimap could be useful.

3. Originally Posted by laserlight
Perhaps you should map the other way instead, or if you need both, then boost bimap could be useful.
ok that was an obvious one. plus i can use multimap not to lose repeated values. sorry for wasting time.

thnx

4. Since a map is accessed by key I fail to see what sorting it accomplishes.