tags:

views:

49

answers:

3

for example we have map

map<char,int>mymap;
mymap['a']=101;
mymap['c']=45;
mymap['b']=76;
mymap['d']=98;

i know that if we iterate through map it will print element according to following way

a>=101;
b>=76;
c>=45;
d>=98;

how do such that small keys refer small values? or

a-45
b-76
c-98
d-101

? thanks

+3  A: 

If I'm understanding you correctly, you do not want to permanently associate values at all, you're wanting to order two different sets of values, and then line them up together at some point. In which case, do not use a std::map. You want two different std::set (or multiset if you want to allow duplicate values) which orders the values separately. Then iterate through the two together at some point.

paul
A: 

You are going to have to do it on your own, map does not iterate over values like that. One option is to use a second map where the keys and values are swapped (if you can have duplicate values, use a multimap).

mos
A: 

You should try using boost multi-index for that, less overhead than using two sets/maps and roughly the same speed.

tsiki