home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / SORT.C < prev    next >
Encoding:
Text File  |  1984-09-02  |  687 b   |  27 lines

  1.    sort(a,n)
  2.  
  3.         /* this subroutine performs an in place sort of */
  4.         /* a one dimensional array using the shell-metzner */
  5.         /* method. */
  6.  
  7.         /* a =  the array to be sorted to ascending order */
  8.         /* n =  the number of elements in the array */
  9.         /* t =  temporary element holder for swap */
  10.  
  11.         float a[];
  12.         int n;
  13.    {
  14.         float t;
  15.         int i,j,k;
  16.  
  17.         for (k = n/2; k > 0; k /= 2)
  18.           for (i = k; i < n; i++)
  19.             for (j = i-k; j >= 0 && a[j] > a[j+k] ; j-=k)
  20.               {
  21.                 t = a[j];
  22.                  a[j] = a[j+k];
  23.                    a[j+k] = t;
  24.  
  25.               }
  26.    }
  27.