Sample of the Kind of Code that Can Go into a Test Driver Program


#include "BST2.h" 

int main ()
{
  treeItemType Item ;
  bstClass tree, tree2 ;
  bool success ;

    /* Build tree */
  Item.setKey("Mary") ;
  tree.SearchTreeInsert(Item, success);
  Item.setKey("Gerry") ;
  tree.SearchTreeInsert(Item, success);
  Item.setKey("Terry") ;
  tree.SearchTreeInsert(Item, success);
  Item.setKey("Larry") ;
  tree.SearchTreeInsert(Item, success);

    /* Build tree2 */
  Item.setKey("Gerry") ;
  tree2.SearchTreeInsert(Item, success);
  Item.setKey("Larry") ;
  tree2.SearchTreeInsert(Item, success);
  Item.setKey("Mary") ;
  tree2.SearchTreeInsert(Item, success);
  Item.setKey("Terry") ;
  tree2.SearchTreeInsert(Item, success);

  cout << "Printing tree: " << endl << endl ;
  tree.Print() ;
  cout << endl ;

  cout << "Printing tree2: " << endl << endl ;
  tree2.Print() ;
  cout << endl ;

  cout << "Printing the number of leaves in tree: " << endl << endl ;
  cout << tree.LeafCount() << endl ;
  cout << endl ;

  cout << "Printing the number of leaves in tree2: " << endl << endl ;
  cout << tree2.LeafCount() << endl ;
  cout << endl ;

  cout << "Getting ancestors of Larry in tree: " << endl << endl ;
  tree.Ancestors("Larry") ;
  cout << endl << endl ;

  cout << "Getting ancestors of Terry in tree2: " << endl << endl ;
  tree2.Ancestors("Terry") ;
  cout << endl << endl ;

  cout << "Testing to see if tree is similar to itself." << endl << endl ;
  if (tree.SimTrees(tree)) cout << "YES" ; else cout << "NO" ;
  cout << endl << endl ;

  cout << "Testing to see if tree is similar to tree2." << endl << endl ;
  if (tree.SimTrees(tree2)) cout << "YES" ; else cout << "NO" ;
  cout << endl << endl ;

  return 0 ;
}