| | | | | |

Inorder Iterator Initialization (Stack Based)

Compare with algorithm in earlier slide!

  void InorderBTIterator<C>::Init(Node* n)
  // only intended to be used with n = root_
  {
    if (n == nullptr) return;
    stk_.Clear();
    stk_.Push(n);
    while (n != nullptr && n->HasLeftChild())
    {
      n = n->lchild_;
      stk_.Push(n);
    }
    while (Valid() && stk_.Top()->IsDead())
      Increment();
  }

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