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


Linear probing sort (Pascal version available)


sort( r, lo, up ) ArrayToSort r; int lo, up; {ArrayToSort r1; int i, j, uppr; uppr = up + (UppBoundr-up)*3/4; for (j=lo; j<=up; j++) r1[j] = r[j]; for (j=lo; j<=UppBoundr; j++) r[j].k = NoKey; for (j=lo; j<=up; j++) { for ( i=phi(r1[j].k,lo,uppr); r[i].k != NoKey; i++) { if ( r1[j].k < r[i].k ) { r1[j-1] = r[i]; r[i] = r1[j]; r1[j] = r1[j-1]; }; if ( i > UppBoundr ) Error; } r[i] = r1[j]; }; for (j=i=lo; j<=UppBoundr; j++) if ( r[j].k != NoKey ) r[i++] = r[j]; while ( i <= UppBoundr ) r[i++].k = NoKey; };

C source (417.sort.c) Pascal source (417.sort.p)



© Addison-Wesley Publishing Co. Inc.