Map Container & Sorting :: STL

Started by
2 comments, last by kuphryn 21 years, 7 months ago
Hi. Is it possible to sort a map *by value* instead of by key? Moreover, is it possible to declare a map that with a custome sorting algorithm that sorts accord to value? If yes, please give a sample of the sorting function. I can create the function object, but I need to know the parameter. Thanks, Kuphryn
Advertisement
The way I see it, sorting a map by value is illogical. Maps are sorted implicitly because of the way they''re done, they''re not sorted because it has to be (though we often take advantage of that).

You can provide your own operator as a template argument, but it will only be used to compare the keys.

What are you trying to do exactly?

----------------
Blaster
Computer game programmer and part time human being
Strategy First - http://www.strategyfirst.com
BlasterSoft - http://www.blastersoft.com
No point sorting by value, because your lookups are on the key.

Maybe you want a set rather than a map.

But as Blaster said, since what you asked for doesn''t make sense, let us know what you''re trying to achieve and maybe we can help.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Okay. Thanks.

The algorithm I am working on a probably simple for most programmers. Nonetheless, I want to come up with my own solution instead of posting it and home someone else solve it.

Hey, I always appreciate help from members.

Kuphryn

This topic is closed to new replies.

Advertisement