Recursive Traversal Method: PrintIterative
The goal for this
exercise
is to implement the
binary search tree’s Print method, in C# source code.
This exercise is intended as more of an open-ended, challenging exercise.
You will need to go beyond what has been covered in the book/lecture, and apply
what you’ve learned previously to do this exercise.
What
you need to do for this exercise:
- In the provided starter
solution, there is a project named something like
03_PCE_StudentCodeer, there is a class named BinarySearchTree.
For this exercise, you
should implement the ‘PrintIterative’ method using iteration instead of
recursion.
Instead of writing this
as a recursive method, use a loop and a Stack (of references to
BSTNodes) to accomplish the goal of printing out (in ascending order)
all the values in the tree.
Before you try writing
the code for this part, spend some time thinking about how to use the
stack to simulate the recursive calls. If you don't have a solid
game plan going into this, you won't be able to start it. Feel
free to discuss this on the Google Group, or ask the instructor for
hints, or verify that your approach sounds reasonable before you start
coding.