按降序排序向量 [英] sorting a vector in descending order

查看:309
本文介绍了按降序排序向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用

std::sort(numbers.begin(), numbers.end(), std::greater<int>());

std::sort(numbers.rbegin(), numbers.rend());   // note: reverse iterators

按降序排序向量?

推荐答案

如果没有别的,第一个版本是方式更清楚您的意图。我实际上必须检查自己,第二个版本真正排序相反的顺序...

If nothing else, the first version is way clearer on your intent. I actually had to check myself that the second version really sorts in reverse order...

这篇关于按降序排序向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆