[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Shellsort for fixed increments


int Increments[] = {34807,15823,7193,3271,1489, 677,307,137,61,29,13,5,2,1,0}; sort( r, lo, up ) ArrayToSort r; int lo, up; {int d, i, id, j; ArrayEntry tempr; for ( id=0; (d=Increments[id]) > 0; id++ ) { /*** Do linear insertion sort in steps size d ***/ for ( i=up-d; i>=lo; i-- ) { tempr = r[i]; for ( j=i+d; j<=up && (tempr.k>r[j].k); j+=d ) r[j-d] = r[j]; r[j-d] = tempr; } } }

C source (414b.sort.c)



© Addison-Wesley Publishing Co. Inc.