Sort: quicksort: how to use qsort
#include <stdio.h>
#include <stdlib.h>
int values[] = { 4, 1, 10, 9, 2, 5 };
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main ()
{
int i;
qsort (values, 6, sizeof(int), compare);
for (i = 0; i < 6; i++)
{
printf ("%d ",values[ i ]);
}
return 0;
}
Related examples in the same category