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