Ejemplo n.º 1
0
        private TreapNode Remove(TKey key, TreapNode tree)
        {
            if (tree == null)
            {
                return(null);
            }

            int result = _comparer.Compare(key, tree.Key);

            if (result < 0)
            {
                tree.Left = Remove(key, tree.Left);
            }
            if (result > 0)
            {
                tree.Right = Remove(key, tree.Right);
            }
            if (result == 0)//key is found
            {
                --_nodesCount;
                tree = tree.DeleteRoot();
            }
            return(tree);
        }