BST:Print Beneath Node

advertisement
Recursive Traversal Method: PrintBeneathNode
The goal for this exercise is to implement the binary search tree’s PrintBeneathNode
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:
1. In the provided starter solution, there is a project named PCE_Starter, there is a
class named BinarySearchTree. For this exercise, you should implement the
‘PrintBeneathNode’ method. Feel free to do this using recursion, using iteration, or
using a combination of the two.
2. Calling PrintBeneathNode( X ) will first find the node with the value X, and if it finds it, it
will print (in normal, ascending order) all the values at (or beneath) that node. If it doesn’t
fit a node with the value X then it will print nothing.
Let’s say that you have the following tree:
10
5
1
12
7
2
Let’s examine a couple of examples:
a. PrintBeneathNode( 1 ) should print “1, 2”
b. PrintBeneathNode( 5 ) should print “1, 2, 5, 7”
c. PrintBeneathNode( 7 ) should print “7”
d. PrintBeneathNode( 12 ) should print “12”
e. PrintBeneathNode( 15 ) should print nothing
3. You should make sure to add in some tests (perhaps in Main, perhaps in a
separate, stand-alone class for testing) that will call your method a couple of
different times.
4. Once you’ve completed the above tasks, you should run the tests in the
NUnit_Tests_BST_Print_Beneath_Node 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. Because this exercise is not marked ‘Hand In’, any failing tests for this
exercise will NOT count against your grade for these PCEs.
Download