I frequently use maps to store pairs of data. A large percent of the time I use it to store a mapping between a value and how many times it occurred. What I would like to do in one particular scenario is to provide the output sorted by the value (in this case, the long) rather than the key (in this case, a string). Is there a built-in way to do this or do I need to iterate through the map and check whether my current value is the highest, etc.?
winbatch
7
Posting Pro in Training
Recommended Answers
Jump to PostYou can't change the ordering of a map.
You want to copy the contents of your map to a datatype such as a vector, and then sort the vector by the value. You can do this using iterators.
All 4 Replies
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
winbatch
7
Posting Pro in Training
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
winbatch
7
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.