if it helps here is cpp file provided to us by our teacher.
Code:
/* To compile this program, do the following
aCC olab10BSTreeMain.cpp BSTree.cpp
To execute with test data file
a.out < /nfshome/csal/public_html/spring.10/2170/olab10sp10.dat
uses exceptions
As always let me know if there are syntax errors in program
*/
#include <iostream>
#include "BSTree.h"
using namespace std;
int main()
{
BSTree MyTree; // A binary search tree used in examples
// See what happens when an empty tree is printed
cout << "An empty tree:" << MyTree << "*" << endl;
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cin >> MyTree; // read's into
cout << "Tree after first read: " << MyTree << endl;;
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
MyTree.Insert("into"); // insert new root
cout << "Tree after insert: " << MyTree << endl;;
cin >> MyTree; // read's insert
cout << "Tree after second read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cin >> MyTree; // read's into
cin >> MyTree; // read's link
cin >> MyTree; // read's list
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cin >> MyTree; // read one string into the tree
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cin >> MyTree; // read's next
cin >> MyTree; // read's last
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cout << "Inorder traversal: " << endl;
MyTree.InOrderTraversal();
cout << endl;
cout << "Preorder traversal: " << endl;
MyTree.PreOrderTraversal();
cout << endl;
cout << "Postorder traversal: " << endl;
MyTree.PostOrderTraversal();
cout << endl;
cin >> MyTree; // read's link
cin >> MyTree; // read's insurance
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cout << "Inorder traversal: " << endl;
MyTree.InOrderTraversal();
cout << endl;
cout << "Preorder traversal: " << endl;
MyTree.PreOrderTraversal();
cout << endl;
cout << "Postorder traversal: " << endl;
MyTree.PostOrderTraversal();
cout << endl;
cin >> MyTree; // read's help
cin >> MyTree; // read's insert
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cout << "Inorder traversal: " << endl;
MyTree.InOrderTraversal();
cout << endl;
cout << "Preorder traversal: " << endl;
MyTree.PreOrderTraversal();
cout << endl;
cout << "Postorder traversal: " << endl;
MyTree.PostOrderTraversal();
cout << endl;
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cout << "Inorder traversal: " << endl;
MyTree.InOrderTraversal();
cout << endl;
cout << "Preorder traversal: " << endl;
MyTree.PreOrderTraversal();
cout << endl;
cout << "Postorder traversal: " << endl;
MyTree.PostOrderTraversal();
cout << endl;
cin >> MyTree; // read's justice
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cout << "Inorder traversal: " << endl;
MyTree.InOrderTraversal();
cout << endl;
cout << "Preorder traversal: " << endl;
MyTree.PreOrderTraversal();
cout << endl;
cout << "Postorder traversal: " << endl;
MyTree.PostOrderTraversal();
cout << endl;
cin >> MyTree; // read's just
cout << "Tree after read: " << MyTree << endl; // This does inorder traversal
cout << "Count: " << MyTree.Count() << endl;
try
{
cout << "First String: " << MyTree.First() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
try
{
cout << "Last String: " << MyTree.Last() << endl;
}
catch (NonExistent myexception)
{
cerr << "There are data itemd in the tree" << endl;
}
cout << "Inorder traversal: " << endl;
MyTree.InOrderTraversal();
cout << endl;
cout << "Preorder traversal: " << endl;
MyTree.PreOrderTraversal();
cout << endl;
cout << "Postorder traversal: " << endl;
MyTree.PostOrderTraversal();
cout << endl;
// test copy constructor
BSTree CopyTree(MyTree);
cout << "Copy Tree: " << CopyTree << endl;;
cout << "end of main"<<endl;
return 0;
}