CS 206: Data Structures
Exercise#17

Due on Thursday, April 24

Implement a class for the Binary Search Tree data stype (as presented in class on Thursday, 4/17). Test your implementation using a main method in the implemented class. Specifically, use the following commands:

A. Use the add method to add the following strings to the BST:

  1. Cambridge
  2. Crapo
  3. Your birth place
  4. Bryn Mawr
  5. Boring
  6. Hell
  7. Walla Walla
  8. Surprise
  9. Joseph
  10. Romance
  11. Mars
  12. Nuttsville
  13. Rough and Ready
  14. Dynamite
  15. Good Grief

After adding the above, do a preorder, postorder, and inorder traversal (printing out each node as you visit). Also print out the number of entries in the tree, and its height.

B. Clear the tree, and print out the number of items and its height. Then add the above towns in ascending order. Print out the resulting tree's size, and height, and also the results of all three tree traversals.

Hand in a complete prinout of your program along with the output.

Back to CS206 Course Materials