keyboard

CoSc2030: Computer Science II

Fall Semester 2007
Instructor: Dr. Thomas Bailey

Lab 10: String Binary Search Trees

In this lab, you will write a BinStringTree.h file that contains some basic functionality of a binary tree that contains strings as its values; and aBinStringDriver.cpp which will contain the main() and act as the client code. Write the BinStringTree.h in the same format as the last lab's BinTree.h file, that is, for each method written, write a version of that method that is accessible to the BinStringDriver, and a static version that is called by the public method and that performs the actual manipulations of the tree.

Lab Assignment:

  1. Create a constructor that constructs an empty tree.


  2. Now create method insert(String) that takes a string value that will be inserted into a new node created in the appropriate position in the tree.


  3. Write a method called preorder() that prints the contents of the tree using preorder traversal.


  4. Now write a method called inorder() that prints the contents of the tree using inorder traversal.


  5. Write a method called find(String) that searches for a matching string in the tree.


  6. Write a method called destroyTree(const Node * ptr), that will be called by ~BinStringTree() (the destructor), that destroys the entire tree.

    Extra credit problem:

  7. Write a method called remove(String) that searches for the node with the same string value as the method's parameter, and removes that node from the tree, while preserving the search tree property of the reamining nodes.

Turn In:

Upload BinStringTree.h with your name in comments at the top of the file, and your Lab10_YourName_Driver.cpp, You have until one week after the lab date to turn in this lab.

<< CoSc2030 Home
Copyright © 2005 Thomas Bailey