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;
}
}
}
|