| | | | | |

Binary Tree Iterator Algorithms: General Patterns

Initialize(bt)
{
  n = bt.root;                       // always enter tree at root
  ...                                // specific to iterator type
  while (n->IsDead()) Increment();   // skip dead nodes
}

Increment()
{
  ...                                // specific to iterator type
}

NextNode()                           // iterator ++()
{
  do Increment();                    // advance at least once
  while (n->IsDead());
}

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