How to print value of a hash map according to increasing/decreasing order of key in c++? -
if have map,
map <int,int> m;
and following key value pair (-2,3) , (-14,8) , (4,8), (6,12) , (3,76)
now if want print value in increasing order of keys,then how print ?
o/p
8 3 76 8 12
the keys in std::map
ordered default (using operator<
). can iterate on map:
for (std::map<int, int>::iterator = m.begin(); != m.end(); i++) { cout << i->second << "\n"; }
Comments
Post a Comment