对长度是length的数组prt进行按大到小排列这个怎么写?
如题!!
/** * file_name: qsort_int.c * description: * * version: 1.0 * created: 23:25 2009-7-24 * revision: none * compiler: VC6.0 * * author: prankmoon@* company: */ #include <stdio.h> #include <stdlib.h> #define MAXLEN 5 int compare_int(const int *n, const int *m); int main(int argc, char *argv[]) { int array_int[MAXLEN] = {2, 4, 3, 1, 5}; qsort(array_int, MAXLEN, sizeof(int), (int (*)(const void *, const void *))compare_int); // we use qsort /* we print the sorted array elements */ int i; for (i=0; i<MAXLEN; i++) { printf("%d ", array_int[i]); } printf("\n\n"); return 0; } /* our compare routine */ int compare_int(const int *n, const int *m) { return (*m - *n); // sort in decreasing order; *n - *m means increasing order }