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


Shellsort (Pascal version available)


sort( r, lo, up ) ArrayToSort r; int lo, up; {int d, i, j; ArrayEntry tempr; for ( d=up-lo+1; d>1; ) { if (d<5) d = 1; else d = (5*d-1)/11; /*** 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 (414.sort.c) Pascal source (414.sort.p)



© Addison-Wesley Publishing Co. Inc.