| | | | | |

Binary Tree Iterator Algorithms: Levelorder

Requires control queue "q"
Location is q.Front()

Initialize(bt)
{
  q.Clear();
  q.Push(bt.root);                    // always enter tree at root
  while (n->IsDead()) Increment();    // skip dead nodes
}

Increment()
{
  q.Push(q.Front()->leftChild);       // push left child current location
  q.Push(q.Front()->rightChild);      // push right child current location
  q.Pop();                            // go to next location
}

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