/* Binary insertion sort */
sort( r, lo, up )
ArrayToSort r;
int lo, up;
{int i, j, h, l;
ArrayEntry tempr;
for ( i=lo+1; i<=up; i++ ) {
tempr = r[i];
for ( l=lo-1, h=i; h-l > 1; ) {
j = (h+l)/2;
if ( tempr.k < r[j].k ) h = j; else l = j;
}
for ( j=i; j>h; j-- ) r[j] = r[j-1];
r[h] = tempr;
}
}
|