- qsort
- sort
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int cmp(const void *a, const void *b) {
return *(int*)a - *(int*)b;
}
bool cmpHeap(int a, int b) {
return (b < a);
}
int main()
{
int a[100], n = 100;
for (int i = 0; i < n; i++) {
a[i] = rand();
}
qsort(a, n, sizeof(int), cmp);
// STL 函数可选加入 cmp 函数
sort(a, a + n, cmpHeap);
for (int i = 1; i <= n; i++) {
cout << a[i-1] << " ";
}
return 0;
}