| | | | | |

Inorder Iterator Incrementation (Stack Based)

Compare with algorithm in earlier slide!

  void InorderBTIterator<C>::Increment()
  {
    if ( stk_.Empty() )
      return;
    Node * n;
    if ( stk_.Top()->HasRightChild() )
    {
      n = stk_.Top()->rchild_;
      stk_.Push(n);
      while ( n != nullptr && n->HasLeftChild() )
      {
        n = n->lchild_;
        stk_.Push(n);
      }
    }
    else
    {
      do
      {
        n = stk_.Top();
        stk_.Pop();
      }
      while( !stk_.Empty() && stk_.Top()->HasRightChild() && n == stk_.Top()->rchild_ );
    }
  }

| | Top of Page | 14. BST Iterators - 25 of 41