Trying to delete a node from BST. After the execution, the node still persists in the tree. How can I implement it properly?
public void deleteNode(TreeNode removeNode, TreeNode root)
{
if(removeNode.Left==null && removeNode.Right==null) //0 children
{
removeNode = null;
}
else if(removeNode.Left==null)//1 children
{
removeNode = removeNode.Right;
}
else if(removeNode.Right==null)//1 children
{
removeNode = removeNode.Left;
}
else // 2 children
{
int successorValue = this.getSuccessor(removeNode, root);
TreeNode successor = this.search(successorValue,root);
removeNode.data = successor.data;
deleteNode(successor, root);
}
}