I have been stuck on an algorithm that requires unique values sorted in descending order. Since the need is unique, I thought set is the best data structure to be used here, but I guess set by default stores the value in non-decreasing order, how do I make it store in non-increasing order?
Other than the fact that I can let it store in ascending order and then reverse the set, is there any other modification that I can do?
CodePudding user response:
How about using std::set<int, std::greater<int>> mySet{}
? By default it's using std::less if I recall correctly.
CodePudding user response:
The order of the set can be changed by changing/defining operator < for the objects stored in your set.