Реферат: Динамические структуры данных: двоичные деревья
else
if x > Tree^.inf
then Tree^.R := Delete(Tree^.R, x) {случай 1}
else
begin {случай 1}
P := Tree;
if Tree^.R=nil
then Tree:=Tree^.L
else if Tree^.L=nil
then Tree:=Tree^.R
else begin
v := Tree^.L;
while v^.R^.R <> nil do v:= v^.R;
Tree^.inf := v^.R^.inf;
P := v^.R;
v^.R :=v^.R^.L;
end;
dispose(P);
end;
Delete := Tree
end;
{C++}
BinTree * Delete(BinTree *Tree, BT x)
{ BinTree* P, *v;
if (!Tree) cout << "такого элемента в дереве нет!" << endl;
else if (x < Tree->inf) Tree->L = Delete(Tree->L, x);
else if (x > Tree-> inf) Tree->R = Delete(Tree->R, x);
else {P = Tree;
if (!Tree->R) Tree = Tree->L; // случай 1