Binary Search Tree: Insert
The goal for this
exercise
is to implement the
binary search tree’s add method, in C# source code.
What you need to do for
this exercise:
- In the provided
starter solution, there is a project named something like 03_PCE_StudentCode,
in the file named Student_Answers.cs, there is a class named
BinarySearchTree. For this exercise, you should implement the ‘Add’ method, as
described in the online lecture.
- For right now, follow
the lecture’s example and use an interative (loop-based) solution. In a
future exercise you will re-implement this method using a recursive approach)
- Once you’ve completed the above tasks,
you should test out your code in order to make sure that it works.
- A good way to
test your insert routine would be to walk through your test code using the
debugger.
- Another good way to
test your insert routine would be to create a PrintTree routine, and have it
print everything in your binary search tree, using an pre-order traversal.
This won’t give you a perfect picture of the structure of the tree, but it’s
better than the normal in-order traversal (which prints out everything in order,
regardless of the structure of the tree).
We haven’t covered this yet, though, so you are NOT required to do this part of
the exercise.