Skip to content

Instantly share code, notes, and snippets.

@ming2540
Created September 18, 2018 12:16
Show Gist options
  • Save ming2540/2afc77e73a14dc463a1cbe6959563999 to your computer and use it in GitHub Desktop.
Save ming2540/2afc77e73a14dc463a1cbe6959563999 to your computer and use it in GitHub Desktop.
#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