Реферат: Сортировка
if (2*no+1)>k then
begin
SwapHalf(no);
Reg:=true; end else
if (memo^[2*no]<=memo^[no]) and (memo^[2*no+1]<=memo^[no]) then Reg:=true
else Reg:=false;
end;
procedure HalfReg(no: integer);
var next: integer;
begin
next:=no;
while (not Reg(next)) do next:=SwapTops(next);
end;
procedure RegTree;
var i: integer;
begin
for i:=k downto 1 do HalfReg(i);
end;
procedure SwapLeaves(l1, l2: integer);
var t: longint;
begin
t:=memo^[l1];
memo^[l1]:=memo^[l2];
memo^[l2]:=t;
end;
procedure SortMemo(len: integer);
begin
k:=len;
RegTree;