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


Linear insertion sort (Pascal version available)


sort( r, lo, up ) ArrayToSort r; int lo, up; {int i, j; ArrayEntry tempr; for ( i=up-1; i>=lo; i-- ) { tempr = r[i]; for ( j=i+1; j<=up && (tempr.k>r[j].k); j++ ) r[j-1] = r[j]; r[j-1] = tempr; } };

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



© Addison-Wesley Publishing Co. Inc.