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:
- 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.
- 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:
Let’s examine a couple of examples:
- PrintBeneathNode( 1 ) should print “1, 2”
- PrintBeneathNode( 5 ) should print “1, 2, 5, 7”
- PrintBeneathNode( 7 ) should print “7”
- PrintBeneathNode( 12 ) should print “12”
- PrintBeneathNode( 15 )
should print nothing
- 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.