Problem in map sorting

How to use comparator in map?


Please refer to this link.

I have read this article but cannot understand this. In map there are key and value pair. But in this comparator they compare two string a and b. I cannot understand what is this, key or value? I just make a comparator for map which is sorted based on descending order of value and if value is same then ascending order of key. Thank you

It is the key value.


Please refer to this link as well.
Also you could traverse the map and store the required values in a vector of pairs as {value,key}
Then sort the vector.

Thank you. But sir can you please tell me how to use comparator which is sorted based on descending order of value and if value is same then ascending order of key

Actually I don’t think a comparator of that type can be defined or not. And we rarely use comparators for maps.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.