Cawte,
som zaciatocnik a mam problem napisat Heapsort v pascale. Ked vlozim vstup do mojho programu,tak mi to vrati cisla presne v takom poradi v akom som ich tam vlozil. Tu je moj kod:
program sort;
var i,N:longint;
a:array[1..999999] of longint;
procedure vymen(x,y:longint);
var z:longint;
begin z:=x;x:=y;y:=z;end;
procedure hore(i:longint);
begin
while (i>1) and (a[i]<a[i div 2]) do begin
vymen(a[i div 2],a[i]);i:=i div 2;
end;
end;
procedure dole(N:longint);
var i,j:longint;
begin
vymen(a[1],a[N]);dec(N);i:=1;
while true do begin
j:=i;
if (2*i<=N) and (a[2*i]<a[j]) then j:=2*i;
if (2*i+1<=N) and (a[2*i+1]<a[j]) then j:=2*i+1;
if j=i then break;
vymen(a[i],a[j]);i:=j;
end;
end;
BEGIN
readln(N);
for i:=1 to N do read(a[i]);
for i:=2 to N do hore(i);
for i:=N downto 2 do dole(i);
for i:=1 to N do write(a[i],' ');writeln();
END.
Dik za pomoc