void test5()
{
  MyBSTree<int> t;
  
  cout << endl << endl << "***** " << "Test #5" << endl;
  cout << "Tree empty? " << boolalpha << t.isEmpty() << endl;  
  cout << "--" << endl;
  
  try {
    t.findMin();
  }
  catch (Oops err)
  {
    cout << err.m_errormsg << endl;
  }

  try {
    t.findMax();
  }
  catch (Oops err)
  {
    cout << err.m_errormsg << endl;
  }

  return;
}
void test5()
{
	MyBSTree<int> t;

	cout << endl << endl << "***** " << "Test #5" << endl;
	cout << "Tree empty? " << boolalpha << t.isEmpty() << endl;
	cout << "--" << endl;

	try {
		t.findMin();
	}
	catch (string errmsg)
	{
		cout << errmsg << endl;
	}

	try {
		t.findMax();
	}
	catch (string errmsg)
	{
		cout << errmsg << endl;
	}
	cout << "end of testing error !!!\n";
	return;
}
//------------------------------------------------------
void test3()
{
  MyBSTree<string> t;
  MyBSTree<string> t2;
  
  cout << endl << endl << "***** " << "Test #3" << endl;

  t.insert(string("Paul"));
  t.insert(string("John"));
  t.insert(string("George"));
  t.insert(string("Ringo"));
  t.insert(string("Fry"));
  t.insert(string("Leela"));
  t.insert(string("Zoidberg"));

  
  t.print();
  cout << "--" << endl;
  cout << "Testing Operator= " << endl;
  t2 = t;
  t2.print();
  
  cout << "--" << endl;
  cout << "Is it a deep copy? " << endl;
  t2.remove(string("George"));
  t2.remove(string("John"));
  t2.remove(string("Ringo"));
  cout << "-- copy:" << endl;
  t2.print();
  cout << "-- original:" << endl;
  t.print();

  return;
}
//------------------------------------------------------
void test4()
{
  MyBSTree<string> t;
  
  cout << endl << endl << "***** " << "Test #4" << endl;

  t.insert(string("Pizza"));
  t.insert(string("Burger"));
  t.insert(string("HotDog"));
  t.insert(string("Shake"));
  t.insert(string("Fry"));
  t.insert(string("Salad"));
  t.insert(string("Soda"));

  
  t.print();
  cout << "--" << endl;
  cout << "Testing Copy Constructor " << endl;
  MyBSTree<string> t2(t);
  t2.print();
  
  cout << "--" << endl;
  cout << "Is it a deep copy? " << endl;
  t2.remove(string("Pizza"));
  t2.remove(string("Salad"));
  t2.remove(string("Fry"));
  cout << "-- copy:" << endl;
  t2.print();
  cout << "-- original:" << endl;
  t.print();

  return;
}
//------------------------------------------------------
void test6()
{
  MyBSTree<int> t;
  
  cout << endl << endl << "***** " << "Test #6" << endl;
 
  cout << "--" << endl;

  t.insert(7);
  t.insert(5);
  t.insert(9);
  t.insert(4);
  t.insert(6);
  t.insert(13);
  t.insert(10);

  
  t.print();
  
  cout << "--" << endl;
  cout << "Pre Order:" << endl;
  t.printPreOrder();
  
  cout << "--" << endl;
  cout << "Post Order" << endl;
  t.printPostOrder();

  return;
}
//------------------------------------------------------
void test2()
{
	MyBSTree<char> t;

	cout << endl << endl << "***** " << "Test #2" << endl;

	t.insert('F');
	t.insert('A');
	t.insert('C');
	t.insert('G');
	t.insert('B');
	t.insert('S');
	t.insert('K');
	t.insert('U');
	t.insert('L');
	t.insert('K');

	t.print();
	cout << "--" << endl;
	cout << "Min = " << t.findMin() << endl;
	cout << "Max = " << t.findMax() << endl;

	return;
}
Beispiel #7
0
int main() {
	MyBSTree<int> tree;
	tree.add(50);
	tree.add(20);
	tree.add(70);
	tree.add(5);
	tree.add(30);
	tree.add(60);
	tree.add(80);
	tree.add(17);
	tree.add(29);
	tree.add(31);
	tree.add(75);
	tree.add(90);
	tree.add(3);
	tree.preorder();
	cout << "\n";
	tree.inorder();
	cout << "\n";
	tree.postorder();
	cout << "\n";

	//Find height of tree
	cout << "The height of the tree is " << tree.height() << "\n";

	//Remove a node with no children
	cout << "Removing 3\n";
	tree.remove(3);
	tree.inorder();
	cout << "\n";
	tree.add(3);

	//Remove a node with only left child
	cout << "Adding 55\n";
	tree.add(55);
	tree.inorder();
	cout << "\nRemoving 55\n";
	tree.remove(55);
	tree.inorder();
	cout << "\n";

	//Remove a node with only right child
	cout << "Adding 65\n";
	tree.add(65);
	tree.inorder();
	cout << "\nRemoving 65\n";
	tree.remove(65);
	tree.inorder();
	cout << "\n";

	//Remove a node with two children
	cout << "Removing 70\n";
	tree.remove(70);
	tree.inorder();
	cout << "\n";

	//Find root
	cout << "Finding 50\n";
	cout << "50 exists? ";
	cout << tree.exists(50);
	cout << "\n";
	
	//Find value on right side
	cout << "Finding 75\n";
	cout << "75 exists? ";
	cout << tree.exists(75);
	cout << "\n";
	
	//Find value on left side
	cout << "Finding 17\n";
	cout << "17 exists? ";
	cout << tree.exists(17);
	cout << "\n";
	
	//Find non existant value
	cout << "Finding 100\n";
	cout << "100 exists? ";
	cout << tree.exists(100);
	cout << "\n";

	//Clear all nodes
	cout << "Removing all nodes\n";
	tree.clear();
	tree.inorder();
}
//------------------------------------------------------
void test1()
{
  MyBSTree<int> t;
  
  cout << endl << endl << "***** " << "Test #1" << endl;
  
  t.print();
  cout << "Tree empty? " << boolalpha << t.isEmpty() << endl;
    
  cout << "--" << endl;

  t.insert(7);
  t.insert(5);
  t.insert(9);
  t.insert(4);
  t.insert(6);
  t.insert(13);
  t.insert(10);

  
  t.print();
  cout << "Tree empty? " << boolalpha << t.isEmpty() << endl;
  cout << "--" << endl;
  cout << "height = " << t.height() << endl;
  cout << "size = " << t.size() << endl;
  cout << "--" << endl;

  return;
}
//
////------------------------------------------------------
void test6()
{
	MyBSTree<int> t;

	cout << endl << endl << "***** " << "Test #6" << endl;

	cout << "--" << endl;

	t.insert(7);
	t.insert(5);
	t.insert(9);
	t.insert(4);
	t.insert(6);
	t.insert(13);
	t.insert(10);


	t.print();

	cout << "--" << endl;
	cout << "Pre Order:" << endl;
	t.printPreOrder();

	cout << "--" << endl;
	cout << "Post Order" << endl;
	t.printPostOrder();

	t.clear();
	cout << "Testing clear\n";

	cout<<"height is "<<t.height()<<"\n";
	t.print();

	return;
}
Beispiel #10
0
int main()
{
    MyBSTree<int> t;
    try 
    {
        t.findMin();
    }
    catch (Oops err)
    {
        cout << err.getMsg() << endl;
    }
  
    cout << endl << endl << "***** " << "Test #1" << endl;
    
    t.print();
    cout << "Tree empty? " << boolalpha << t.isEmpty() << endl;
        
    cout << "--" << endl;

    t.insert(7);
    t.insert(5);
    t.insert(9);
    t.insert(4);
    t.insert(6);
    t.insert(13);
    cout << "size = " << t.size() << endl;
    t.insert(10);
    cout << "size = " << t.size() << endl;
    t.remove(10);
   // t.print();
    cout << "Tree empty? " << boolalpha << t.isEmpty() << endl;
    cout << "--" << endl;
    //cout << "height = " << t.height() << endl;
    cout << "size = " << t.size() << endl;
    cout << "--" << endl;
    cout<<"penis"<<endl;
    return 0;
}