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

  1. /* select1.c: Illustrate selection sort */
  2.  
  3. #include <stdio.h>
  4.  
  5. #define NELEMS 4
  6.  
  7. main()
  8. {
  9.     int a[NELEMS] = {40, 12, 37, 15};
  10.     size_t i, j;
  11.  
  12.     for (i = 0; i < NELEMS-1; ++i)
  13.         for (j = i+1; j < NELEMS; ++j)
  14.             if (a[i] > a[j])
  15.             {
  16.                 int t = a[i];
  17.                 a[i] = a[j];
  18.                 a[j] = t;
  19.             }
  20.             
  21.     for (i = 0; i < NELEMS; ++i)
  22.         printf("%d\n",a[i]);
  23.     return 0;
  24. }
  25.  
  26. /* Output:
  27. 12
  28. 15
  29. 37
  30. 40
  31. */
  32.