Listing 7 Illustrates a generic Selection Sort

/* select2.c: Use the selection sort function */

#include <stdio.h>

#define NELEMS 4

extern void ssort(void *, size_t, size_t, int (*)(const void *,const void *));
static int comp(const void *, const void *);

main()
{
   size_t i;
   int a[NELEMS] = {40, 12, 37, 15);

   ssort(a,NELEMS,sizeof a[0],comp);

   for (i = 0; i < NELEMS; ++i)
      printf("%d\n",a[i]);
   return 0;
}

static int comp(const void *p1, const void *p2)
{
   int a = * (int *) pl;
   int b = * (int *) p2;
   
   return a - b;
}
/* Output:
12
15
37
40
*/
/* End of File */