如何强制在C++以降序存储值?
我一直被困在一种算法上,该算法需要按降序排序的唯一值。由于需求是唯一的,所以我认为集合是这里要使用的最佳数据结构,但是我想默认设置的值将其值存储在非降低顺序中,我该如何使其以非侵扰顺序存储?
除了我可以让它以上升顺序存储然后逆转集合之外,还有其他我可以做的修改吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何使用
std :: set< int,std :: greem< int> myset {}
?默认情况下,如果我没记错的话,它使用std :: Less
。How about using
std::set<int, std::greater<int>> mySet{}
? By default it's usingstd::less
if I recall correctly.可以通过更改/定义操作员来更改集合的顺序。对于存储在您的集合中的对象。
The order of the set can be changed by changing/defining operator < for the objects stored in your set.