home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_04 / 1104111c < prev    next >
Text File  |  1993-02-05  |  601b  |  37 lines

  1. /* select2.c: Use the selection sort function */
  2.  
  3. #include <stdio.h>
  4.  
  5. #define NELEMS 4
  6.  
  7. extern void ssort(void *, size_t, size_t,
  8.                   int (*)(const void *,const void *));
  9. static int comp(const void *, const void *);
  10.  
  11. main()
  12. {
  13.     size_t i;
  14.     int a[NELEMS] = {40, 12, 37, 15};
  15.  
  16.     ssort(a,NELEMS,sizeof a[0],comp);
  17.     
  18.     for (i = 0; i < NELEMS; ++i)
  19.         printf("%d\n",a[i]);
  20.     return 0;
  21. }
  22.  
  23. static int comp(const void *p1, const void *p2)
  24. {
  25.     int a = * (int *) p1;
  26.     int b = * (int *) p2;
  27.  
  28.     return a - b;
  29. }
  30.  
  31. /* Output:
  32. 12
  33. 15
  34. 37
  35. 40
  36. */
  37.