Beispiel #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);
                }
            }
        }
Beispiel #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;
 }
Beispiel #3
0
 public override void Visit(InnerNode node)
 {
     _root = node;
 }
Beispiel #4
0
 public override void Visit(LeafNode node)
 {
     _root = node;
 }