Recursive Traversal Method: Print

advertisement
Recursive Traversal Method: Print
The goal for this exercise is to implement an interesting variation on the binary
search tree’s Print method, in C# source code, using recursion.
Note that in order to pass the NUnit tests, each value (each integer) should be
printed out on its own line, with nothing else (not even blank spaces) on that line. The
values should be printed out in order, so that the smallest value is printed first and the
largest value is printed last.
What you need to do for this exercise:
1. In the provided starter solution, in a project named something like
03_PCE_StudentCode, in the Student_Answers.cs file, there is a class named
BinarySearchTree. For this exercise, you should implement the ‘Print’ method
using recursion.
This method MUST be implemented using Recursion. You will get no points for a
solution that does not use a recursive approach to solve this problem.
2. Once you’ve completed the above tasks, you should run the tests in the
NUnit_Tests_BST_Print_Recursive class. They should all pass at this point, and if
not, then you should fix your program so that those tests do pass. You can run
the tests using the NUnit support in the provided starter project. You should feel
free to supplement that code with your own test cases if you wish, but you are
neither required nor expected to.
a. NOTE: These tests depend on the normal, non-recursive Add method that
you implemented in the prior lesson– until the Add method correctly adds
nodes to your BST, these tests will fail. While it's great practice to recode this, you should feel free to copy this from the prior lesson, if you
prefer.
b. If you have a working add method from the prior lesson, feel free to copyand-paste that method into this exercise. The objective here is to
implement the Print method, not to get more practice reimplementing the
Add method.
Download