Exemple #1
0
        private void TwoChildsDelete(BinaryNode node)
        {
            BinaryNode next   = FindSuccessor(node);
            BinaryNode parent = next.Parent;

            if (parent == node)
            {
                parent.SetKey(next.Key);
                parent.SetValue(next.Value);
                parent.SetRightNode(next.Right);

                if (next.Right != null)
                {
                    next.Right.SetParentNode(parent);
                }
            }
            else
            {
                parent.SetLeftNode(next.Right);
                if (next.Right != null)
                {
                    next.Right.SetParentNode(parent);
                }

                node.SetKey(next.Key);
                node.SetValue(next.Value);
            }

            next.SetParentNode(null);
            next.SetLeftNode(null);
            next.SetRightNode(null);
        }
Exemple #2
0
        private void OneChildDelete(BinaryNode nodeToDelete)
        {
            BinaryNode child = null;

            if (nodeToDelete.Left != null)
            {
                child = nodeToDelete.Left;
            }
            else
            {
                child = nodeToDelete.Right;
            }

            nodeToDelete.SetKey(child.Key);
            nodeToDelete.SetValue(child.Value);
            nodeToDelete.SetLeftNode(child.Left);
            nodeToDelete.SetRightNode(child.Right);

            child.SetParentNode(null);
            child.SetRightNode(null);
            child.SetLeftNode(null);
        }