Created
September 18, 2018 12:16
-
-
Save ming2540/2afc77e73a14dc463a1cbe6959563999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int comp (const void * elem1, const void * elem2) | |
{ | |
int f = *((int*)elem1); | |
int s = *((int*)elem2); | |
if (f > s) return 1; | |
if (f < s) return -1; | |
return 0; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
int x[] = {4,5,2,3,1,0,9,8,6,7}; | |
int i; | |
// this is sort | |
qsort (x, sizeof(x)/sizeof(*x), sizeof(*x), comp); | |
for ( i = 0 ; i < 10 ; i++) | |
printf ("%d ", x[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment