0%

sort和qsort

sort

1
2
3
4
bool cmp(const int &a, const int &b) {
return a > b;//从大到小
}
sort(a + 1, a + 1 + n, cmp);

qsort

1
2
3
4
int cmp2(const void* a, const void* b) {
return *(int*)b - *(int*)a;//从大到小
}
qsort(a+1, n, sizeof(a[0]),cmp2);

Welcome to my other publishing channels