簡體   English   中英

從高到低排序數組

[英]Sorting an array, from high to low

我有一個包含多個整數的數組,是否有一種常見的方式將其從高到低排序?

#include <algorithm>
#include <functional>
int arr[ 5 ] = { 4, 1, 3, 2, 5 };
std::sort( arr, arr + 5, std::greater< int >() );

將比較器傳遞到排序例程,該例程會反轉常規比較。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM