Mega Code Archive

 
Categories / C / Code Snippets
 

Sort quicksort how to use qsort

#include <stdio.h> #include <stdlib.h> int values[] = { 3, 8, 9, 7, 3, 5 }; int compare (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main () { int j; qsort (values, 6, sizeof(int), compare); for (j = 0; j < 6; j++) { printf ("%d ",values[ j ]); } return 0; }