In-order Traversal: Iterative Implementation

Exercise Open the starter code and complete the implementation of BstOrderedSet.iterator.

Hint 1: You cannot do this recursively (in Java). The iterator needs to "pause" so to speak and wait for call to next to generate (retrieve) the next element.

Hint 2: You will need an auxiliary data structure in the iterator class to keep track of some of the nodes as you traverse the tree, so you can visit those nodes later.

Solution

Please refer to the posted solution code.

Resources

You may find this article on Medium useful: Binary Search Tree Iterator.