Sortowanie Przez Kopcowanie
const SIZE = 20000;
type TFeld = array[1..SIZE] of integer;

procedure heapsort(var f:TFeld);

    procedure genheap(var f:TFeld);             
    var i,j,max,temp:integer;
    begin
        for i := SIZE div 2 downto 2 do begin   
            j:=i;
            while j <= SIZE div 2 do begin
                max := j * 2 + 1;               e }
                if max > SIZE then dec(max)
                else if f[max-1] > f[max] then dec(max);
                if f[j] < f[max] then begin     
                    temp := f[j];
                    f[j] := f[max];
                    f[max] := temp;
                end;
                j := max;
            end;
        end;
    end;

    function popmax(var f:TFeld;heapsize:integer):integer;
    var i,max,temp:integer;
    begin
        popmax := f[1];
        f[1] := f[heapsize];
        i := 1;
        while i <= (heapsize div 2) do begin 
            max := i * 2 + 1;              }
            if max > heapsize then dec(max)
            else if f[max-1] > f[max] then dec(max);
            if f[i] < f[max] then begin     
                temp := f[i];
                f[i] := f[max];
                f[max] := temp;
            end;
            i := max;
        end;
    end;
   var i:integer;
begin
    genheap(f);
    for i:=SIZE downto 1 do f[i] := popmax(f,i);
end;
O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License