Exemple #1
0
 private void addToStack(IAVLTreeNode <T> node)
 {
     while (node != null)
     {
         this.stack.Push(node);
         node = node.LeftChild;
     }
 }
Exemple #2
0
        //public int BalancedFactor => GetHeight(LeftNode) + GetHeight(RightNode);

        private int GetHeight(IAVLTreeNode <int> node)
        {
            if (node == null)
            {
                return(-1);
            }
            return(Math.Max(GetHeight(node.LeftNode), GetHeight(node.RightNode)) + 1);
        }
Exemple #3
0
 public bool MoveNext()
 {
     if (this.pendingNode != null)
     {
         this.addToStack(this.pendingNode);
         this.pendingNode = null;
         return(this.stack.Count > 0);
     }
     if (this.stack.Count > 0)
     {
         IAVLTreeNode <T> node = this.stack.Pop();
         this.addToStack(node.RightChild);
     }
     return(this.stack.Count > 0);
 }
Exemple #4
0
 public AVLTreeNode(T value, IAVLTreeNode <T> parent, IAVLTree <T> tree)
 {
     Value  = value;
     Parent = parent;
     _tree  = tree;
 }
Exemple #5
0
 public void Dispose()
 {
     this.stack    = null;
     this.rootNode = this.pendingNode = null;
 }
Exemple #6
0
 public AVLTreeEnumerator(IAVLTreeNode <T> node)
 {
     this.rootNode = node;
     this.Reset();
 }