home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / dm.lzh / shellsort.c < prev    next >
Text File  |  1995-04-03  |  741b  |  33 lines

  1. /* Shell sort of string v[0] .... v[n-1] into increasing
  2.  * order.
  3.  *    Reference CPL pg. 108.
  4.  */
  5.  
  6. shellsort(filecount)
  7. int filecount;
  8.     {
  9.     int gap, i, j;
  10.     char *temp;
  11.     char *tempfd;
  12.     short attr;
  13.     extern char **nameptr;
  14.     extern char **fildesptr;
  15.     extern short *attrptr;
  16.     
  17.     for (gap = filecount/2; gap > 0; gap = gap / 2)
  18.         for (i = gap; i < filecount; i++)
  19.             for (j = i - gap; j >= 1; j = j - gap){
  20.                 if (strcmp(nameptr[j], nameptr[j+gap]) <= 0)
  21.                     break;
  22.                 temp = nameptr[j];
  23.                 nameptr[j] = nameptr[j + gap];
  24.                 nameptr[j + gap] = temp;
  25.                 tempfd = fildesptr[j];
  26.                 fildesptr[j] = fildesptr[j + gap];
  27.                 fildesptr[j + gap] = tempfd;
  28.                 attr = attrptr[j];
  29.                 attrptr[j] = attrptr[j + gap];
  30.                 attrptr[j + gap] = attr;
  31.                 }
  32.     }
  33.