home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 143_01 / qsort.c < prev    next >
Text File  |  1985-11-14  |  768b  |  27 lines

  1.   /* quick sort for BDS-C; similar to K & L sort p116 & exch p117
  2.     here the two routines are rolled into one srting function.
  3.     This function is required for OTHELLO.C written in BDS-C */
  4.  
  5. qsort( targ, n, length, comp)
  6. char targ[];
  7. int n, length;
  8. int (*comp)();
  9. {
  10.     char temp;
  11.     register int  i, j, e, ind1, ind2, gap;
  12.     for( gap =  n/2; gap > 0; gap /= 2)
  13.     for( i = gap; i < n; i++)
  14.         for( j = i-gap; j >= 0; j -=gap) {
  15.         ind1 = length * j;
  16.         ind2 = (j + gap) * length;
  17.         if ((*comp) (&targ[ind1], &targ[ind2]) <= 0 )
  18.             break;
  19.         /* exchange */
  20.         for( e = 0; e < length; e++, ind1++, ind2++) {
  21.             temp = targ[ind1];
  22.             targ[ind1] = targ[ind2];
  23.             targ[ind2] = temp;
  24.         }
  25.         }
  26. }
  27.