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


Heapsort


procedure sort( var r : ArrayToSort; lo, up : integer ); var i : integer; tempr : ArrayEntry; begin {*** construct heap ***} for i := (up div 2) downto 2 do siftup(r,i,up); {*** repeatedly extract maximum ***} for i := up downto 2 do begin siftup(r,1,i); tempr := r[1]; r[1] := r[i]; r[i] := tempr end end;

C source (415.sort.c) Pascal source (415.sort.p)



© Addison-Wesley Publishing Co. Inc.