Esempio n. 1
0
void HeightTest()
{
	cout << "--------------------------Height Test---------------------------" << endl;

	RedBlackTree<int> tree;
	cout<< "Creat Tree..." << endl;
	cout << "Height: " << tree.Height() << endl;
	cout << "Insert 1" << endl;
	tree.Insert(1);
	cout << "Height: " << tree.Height() << endl <<endl ;
	cout << "Insert 5 Item" << endl;
	tree.Insert(20);
	tree.Insert(3);
	tree.Insert(7);
	tree.Insert(5);
	tree.Insert(6);
	tree.Insert(10);
	tree.Insert(21);
	tree.Insert(23);
	cout << "Height: " << tree.Height() << endl;

	cout << "Verify Red Black Tree..." << endl;
	tree.verify(tree);

	cout << "Remove 1" << endl;
	tree.Remove(1);
	cout << "Height: " << tree.Height() << endl <<endl ;

	cout << "Remove All..." << endl;
	tree.RemoveAll();
	cout << "Height: " << tree.Height() << endl;

	cout << "Verify Red Black Tree..." << endl;
	tree.verify(tree);

	cout << endl;
}
Esempio n. 2
0
void RemoveTest2()
{
	cout << "--------------------------RemoveTest2---------------------------" << endl;

	RedBlackTree<int> tree;
	tree.Insert(20);
	tree.Insert(3);
	tree.Insert(7);
	tree.Insert(5);
	tree.Insert(6);
	tree.Insert(10);
	tree.Insert(21);
	tree.Insert(23);
	cout << endl << "New Tree..." << endl;
	cout << "Verify Red Black Tree..." << endl;
	tree.verify(tree);

	cout << "Remove Root..." << endl;
	tree.Remove(7);
	cout << "Verify Red Black Tree..." << endl;
	tree.verify(tree);

	cout << "New Tree2..." << endl;

	RedBlackTree<int> tree2;
	tree2.Insert(5);
	tree2.Insert(6);
	tree2.Insert(3);
	tree2.Insert(1);
	tree2.Insert(8);
	tree2.Insert(23);
	tree2.Insert(11);
	tree2.Insert(24);
	tree2.Insert(10);
	tree2.Insert(4);
	tree2.Insert(2);
	tree2.Insert(25);
	cout << endl << "Verify Red Black Tree2..." << endl;
	tree2.verify(tree2);

	cout << "Remove 5 Elements (6 24 11 3 8)..." << endl;
	tree2.Remove(6);
	cout << endl << "Verify Red Black Tree2..." << endl;
	tree2.verify(tree2);
	tree2.Remove(24);
	cout << endl << "Verify Red Black Tree2..." << endl;
	tree2.verify(tree2);
	tree2.Remove(11);
	cout << endl << "Verify Red Black Tree2..." << endl;
	tree2.verify(tree2);
	tree2.Remove(3);
	cout << endl << "Verify Red Black Tree2..." << endl;
	tree2.verify(tree2);
	tree2.Remove(8);
	cout << endl << "Verify Red Black Tree2..." << endl;
	tree2.verify(tree2);


	cout << "Create Tree3..." << endl;
	RedBlackTree<int> tree3;
	tree3.Insert(5);
	tree3.Insert(6);
	tree3.Insert(3);
	tree3.Insert(1);
	tree3.Insert(8);
	tree3.Insert(23);
	tree3.Insert(11);
	tree3.Insert(24);
	tree3.Insert(10);
	tree3.Insert(4);
	tree3.Insert(2);
	tree3.Insert(25);

	tree3.Remove(6);
	tree3.Remove(24);
	tree3.Remove(11);
	tree3.Remove(3);

	tree3.Insert(6);

	cout  << "Verify Red Black Tree3..." << endl;
	tree3.verify(tree3);

	cout << "Remove Root..." << endl;
	tree3.Remove(8);

	cout  << "Verify Red Black Tree3..." << endl;
	tree3.verify(tree3);

	cout << endl;
}