Ejemplo n.º 1
0
        public void Add(int e)
        {
            if (_root is LeafNode)
            {
                _root = new InnerNode(e);
            }
            else
            {
                var current = _root;
                InnerNode prev = null;
                while (current is InnerNode)
                {
                    prev = (InnerNode) current;
                    var inner = current as InnerNode;
                    current = inner.Key > e ? inner.Right : inner.Left;
                }

                Debug.Assert(prev != null, "prev != null");
                if (prev.Key > e)
                {
                    prev.Right = new InnerNode(e);
                }
                else
                {
                    prev.Left = new InnerNode(e);
                }
            }
        }
Ejemplo n.º 2
0
 private int GetHeight(Node node)
 {
     if (node is LeafNode)
     {
         return -1;
     }
     var inner = node as InnerNode;
     Debug.Assert(inner != null, "inner != null");
     return Math.Max(GetHeight(inner.Left), GetHeight(inner.Right)) + 1;
 }
Ejemplo n.º 3
0
 public override void Visit(InnerNode node)
 {
     _root = node;
 }
Ejemplo n.º 4
0
 public override void Visit(LeafNode node)
 {
     _root = node;
 }