procedure insert ( new : tree; var pq : tree );
label 9999;
var p : tree;
begin
if pq = nil then pq := new
else if pq^.k >= new^.k then begin
{*** Insert above subtree ***}
new^.left := pq;
pq := new
end
else begin
p := pq;
while p^.left <> nil do
if p^.left^.k >= new^.k then begin
{*** Insert in right subtree ***}
insert( new, p^.right );
goto 9999
end
else p := p^.left;
{*** Insert at bottom left ***}
p^.left := new
end;
9999:
end;
|