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


Replacement selection distribution


insert( n, r ) RecordArray r; int n; {int i; ArrayEntry tempr; tempr = r[n]; for ( ; n>0; n=i) { i = (n-1)/2; if ( r[i].k <= tempr.k ) break; r[n] = r[i]; } r[n] = tempr; }; siftup( r, i, n ) RecordArray r; int i, n; {ArrayEntry tempr; int j; while ( (j=2*i+1) <= n ) { if ( j<n && r[j].k > r[j+1].k ) j++; if ( r[i].k > r[j].k ) { tempr = r[j]; r[j] = r[i]; r[i] = tempr; i = j; } else break; } };

C source (4411.heap.c)



© Addison-Wesley Publishing Co. Inc.