Delete an object from a tree

Posted by mqpasta on Stack Overflow See other posts from Stack Overflow or by mqpasta
Published on 2010-04-02T11:40:53Z Indexed on 2010/04/02 11:43 UTC
Read the original article Hit count: 203

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about binary-trees