greater使内置类型从大到小排序,而less从小到大
#include
#include
using namespace std; int main() { int a[5] = {
4, 1, 5, 3, 2}; sort(a, a + 5, greater<int>()); //由大到小排序 for(int i = 0; i < 5; i++) cout << a[i] << " "; cout<<"\n"; sort(a, a + 5, less<int>()); //由小到大排序(sort一般默认为从小到大,所以less可以省略) for(int i = 0; i < 5; i++) cout<
" ";
return
0; }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/218160.html原文链接:https://javaforall.net
