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


Heap insertion (Pascal version available)


siftup( r, i, n ) RecordArray r; int i, n; {ArrayEntry tempr; int j; while ( (j=2*i) <= 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 (513.sift.c) Pascal source (513.sift.p)



© Addison-Wesley Publishing Co. Inc.