Ejemplo n.º 1
0
        internal static RedBlackNode Add(System.Collections.IComparer comp, RedBlackNode t, object key, object val, Box found)
        {
            if (t is null)
            {
                return(val is null ? new RedNode(key) : new RedValueNode(key, val));
            }
            int c = comp.Compare(key, t.Key);

            if (c == 0)
            {
                found.Value = t;
                return(null);
            }
            var insert = c < 0 ? Add(comp, t.Left, key, val, found) : Add(comp, t.Right, key, val, found);

            if (insert is null)
            {
                return(null);
            }
            return(c < 0
                ? t.AddLeft(insert)
                : t.AddRight(insert));
        }