home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume5 / smallc / part3 / lib / shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  395 b   |  22 lines

  1. /* Shell sort of string v[0] .... v[n-1] into increasing
  2.  * order.
  3.  *    Reference CPL pg. 108.
  4.  */
  5.  
  6. shellsort(v, n)
  7. int v[];
  8. int n;
  9.     {
  10.     int gap, i, j;
  11.     char *temp;
  12.     for (gap = n/2; gap > 0; gap = gap / 2)
  13.         for (i = gap; i < n; i++)
  14.             for (j = i - gap; j >= 0; j = j - gap){
  15.                 if (strcmp(v[j], v[j+gap]) <= 0)
  16.                     break;
  17.                 temp = v[j];
  18.                 v[j] = v[j + gap];
  19.                 v[j + gap] = temp;
  20.                 }
  21.     }
  22.