const
n=100;
var
a:array[1..100]of integer;
i,x:integer;
procedure adjust_down(i,m:integer);
var
x:integer;
begin
while i*2<=m do
begin
i:=i*2;
if (i
if a[i]>a[i div 2] then
begin
x:=a[i div 2];
a[i div 2]:=a[i];
a[i]:=x;
end else break;
end;
end;
begin
randomize;
for i:=1 to n do
a[i]:=random(65535)-32767;
for i:=n div 2 downto 1 do
adjust_down(i,n);
for i:=n downto 2 do
begin
x:=a[i];
a[i]:=a[1];
a[1]:=x;
adjust_down(1,i-1);
end;
for i:=1 to n do
write(a[i]:8);
end.
去vijos上找吧,那上面的分类里应该有堆
合并果子 简单应用堆的一道题
冒泡排序,二分查找还是普通排序 ?说清楚