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

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