Esempio n. 1
0
//
////------------------------------------------------------
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;
}
Esempio n. 2
0
//
////------------------------------------------------------
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;
	t.clear();
	t2.clear();
}
Esempio n. 3
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();
}