I have a Find function in order to find an element from a BST
private Node Find(ref Node n, int e)
{
if (n == null)
return null;
if (n.Element == e)
return n;
if (e > n.Element)
return Find(ref n.Right, e);
else
return Find(ref n.Left, e);
}
and I use following code in order to get a node and then set this node to null.
Node x = bsTree.Find(1);
x = null;
bsTree.Print();
supposedly, this node should be deleted from Tree as it is set to null but it still exists in tree.
I had done this before but this time missing something and no idea what.
you have to get somehow the parent node of the one you want to remove.
Then if the node to remove is the left one you do
if it’s the right:
With this method you have to be aware that you will remove the node from the tree but also all its descendants