我试图使用c++来按升序和降序对数组进行排序。我只使用桶排序创建了升序:
void bucketSort (int data[], int n)
{
int x = 65537; //range is [1,65536]
int buckets[x]; //Create empty buckets
for (int i = 0; i < x; i++) //Initialize all buckets to 0
buckets[i] = 0;
//Increment the # of times each element is present in the input
//array. Insert them in the buckets
for (int i = 0; i < n; i++)
buckets[data[i]]++;
//Sort using insertion sort and link
for (int i = 0, j = 0; j < x; j++)
for (int k = buckets[j]; k > 0; k--)
data[i++] = j;
}但我不知道怎么按降序来做。任何帮助都会很好。
https://stackoverflow.com/questions/32167578
复制相似问题