I’m reading the Cormen algorithms book (binary search tree chapter) and it says that there are two ways to traverse the tree without recursion:
using stack and
a more complicated but elegant
solution that uses no stack but
assumes that two pointers can be
tested for equality
I’ve implemented the first option (using stack), but don’t know how to implement the latter.
This is not a homework, just reading to educate myself.
Any clues as to how to implement the second one in C#?
Sure thing. You didn’t say what kind of traversal you wanted, but here’s the pseudocode for an in-order traversal.
To get pre- or post-order, you rearrange the order of the blocks.