Code is: C language in the quick line of writing, to join the header file <stdlib.h>
Qsort (array name, length, data type size, comparison operator);
#include <stdio.h> #include <string.h> #include <stdlib.h>int cmp (const void *a, const void *b) {return * (int *) a-* (int *) b; Sort from small to large such as output: 1 2 3 4 5}int main () {int a[100];int n;int I, J;while (scanf ("%d", &n)!=eof) {for (i=0; i<n; i++) { scanf ("%d", &a[i]);} Qsort (A, n, sizeof (int), CMP), for (j=0; j<n; J + +) {printf ("%d%c", A[j], i==n-1? ' \ n ': ');}} return 0;}
#include <stdio.h> #include <string.h> #include <stdlib.h>int cmp (const void *a, const void *b) {return * (int *) b-* (int *) A; Sort from large to small such as output: 5 4 3 2 1}int main () {int a[100];int n;int I, J;while (scanf ("%d", &n)!=eof) {for (i=0; i<n; i++) { scanf ("%d", &a[i]);} Qsort (A, n, sizeof (int), CMP), for (j=0; j<n; J + +) {printf ("%d%c", A[j], i==n-1? ' \ n ': ');}} return 0;}
C-language "quick sort" function notation