如何强制在C++以降序存储值?

发布于 2025-01-31 12:27:30 字数 146 浏览 2 评论 0原文

我一直被困在一种算法上,该算法需要按降序排序的唯一值。由于需求是唯一的,所以我认为集合是这里要使用的最佳数据结构,但是我想默认设置的值将其值存储在非降低顺序中,我该如何使其以非侵扰顺序存储?

除了我可以让它以上升顺序存储然后逆转集合之外,还有其他我可以做的修改吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小清晰的声音 2025-02-07 12:27:30

如何使用std :: set< int,std :: greem< int> myset {}?默认情况下,如果我没记错的话,它使用std :: Less

How about using std::set<int, std::greater<int>> mySet{}? By default it's using std::less if I recall correctly.

会发光的星星闪亮亮i 2025-02-07 12:27:30

可以通过更改/定义操作员来更改集合的顺序。对于存储在您的集合中的对象。

The order of the set can be changed by changing/defining operator < for the objects stored in your set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文