Deletion process:
Public VoidDelnode (IntX)//The deleted node value isXNode
{
Treenode P, Q, R, T;
P = root;
Q =Null;// PPoint to the node to be compared,QIsPForward node
While(P! =Null& P. Data! = X)
{
If(X <p. Data)
{
Q = P;
P = P. leftnode;
}
Else
{
Q = P;
P = P. rightnode;
}
}
If(P =Null)
Console. Write ("error ");
Else If(P. leftnode =Null)//No left decision tree at the deleted Node
{
If(Q =Null)
T = P. rightnode;
Else If(Q. leftnode = P)
Q. leftnode = P. leftnode;
Else
Q. rightnode = P. rightnode;
}
Else
{
//Find the rightmost node in the left decision tree of the deleted node, that is, the value is exactly lessXNode
R = P. leftnode;
While(R. rightnode! =Null)
R = R. rightnode;
R. rightnode = P. rightnode;
If(Q =Null)
T = P. rightnode;
Else If(Q. leftnode = P)
Q. leftnode = P. leftnode;
Else
Q. rightnode = P. rightnode;
}
}< br> in this instance, the data type is int. You can change it to the icomparable interface to implement any type.