Overview


Trees also offer user-friendly traversal via "iterators".

Like node removal, design and coding of the iterator tends to require a bit of tinkering. Don't be surprised if you run into a few stack overflows along the way...

Algorithms


There are different approaches for iteration, and you might invent your own.

Here are some references:


One Approach


In addition to the algorithm references listed above, here is another approach.

Here is the general idea:


Hint: You know you will always be moving to right (or upward to ancestor) when advancing.