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


Heap insertion


procedure insert( new : ArrayEntry; var r : RecordArray ); var i, j : integer; flag : boolean; begin n := n+1; j := n; flag := true; while flag and (j>1) do begin i := j div 2; if r[i].k >= new.k then flag := false else begin r[j] := r[i]; j := i end end; r[j] := new end;

C source (513.ins.c) Pascal source (513.ins.p)



© Addison-Wesley Publishing Co. Inc.