CS 153 Data Structures I

Assignment #10

Due: 4/5/01

Purpose: to learn about binary search trees (BST)
Options: you can write this program in either dialog or console mode

Description of operation:

  1. The user should first enter the name of a file.  You can think of this file as being a small dictionary.  The words in the file should be read and stored in the BST. 
  2. When the program reaches end-of-file display all of the words in the binary search tree by calling
  3. Then, the user will enter the name of a second file.  This second file can be thought of as a list of words to check against the dictionary.  As you go through the second file,  you should check to see if the word is already in the BST.  If the word is there, do nothing, and go on to the next word.  If the word is not in the BST, it should be added to the BST.
  4. Again, when the program reaches end-of-file display all of the words in the binary search tree.
  5. In this program you will be inserting nodes into a container, so the concepts are familar.  However, instead of a node having a previous and next pointer, each node will have a left child and a right child.  The struct that you will need is shown below.

struct BNode
{

BNnode();      // Constructor
CString data;
BNode * LC;
BNode * RC;

};

You will also need a BST Class.  The class should be able to insert a node, find a node, and traverse the tree for output purposes.  Your BST class might look something like the one shown below.

class BST
{
public:
   BST();
   ~BST();
   void Insert(CString);
   bool Find(CString);
   void Display(CListBox &);
private:
   BNode * root;
   void HelpDisplay(CListBox &, BNode*);

};

How the Display function(s) should work:

  1. From a ...Dlg function you will call myBST::Display(here is the ListBox to use)
  2. BST::Display calls BST::HelpDisplay(here is the ListBox, here is the starting position - ROOT)
  3. BST::HelpDisplay(CListBox & box, BNode * current ) //does all of the work of displaying the nodes

Sample data file A

Sample data file B