Sort: quicksort: how to use qsort : Quick sort « Data Structure Algorithm « C / ANSI-C






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

1.The Quicksort
2.A Quicksort for stringsA Quicksort for strings
3.A Quicksort for filesA Quicksort for files
4.How to use sysmtem quick sortHow to use sysmtem quick sort
5.Quick sort on two dimensional string arrayQuick sort on two dimensional string array
6.Use the system quick sort
7.A Quicksort for structures of type address