Exemplo n.º 1
0
void CopyTest()
{
	cout << "--------------------------CopyTest---------------------------" << endl;

	RedBlackTree<int> tree;
	cout << "Create Tree..." << endl;
	tree.Insert(6);
	tree.Insert(77);
	tree.Insert(1);
	tree.Insert(9);
	tree.Insert(11);
	tree.Insert(5);

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

	cout << "Size: " << tree.Size() << endl;
	RedBlackTree<int> treeC(tree);
	cout << "Perform Copy Tree..." << endl;
	cout << "Size of Copy: " << treeC.Size() << endl;

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

	cout << "Remove 2 Elements of Copy" << endl; 
	treeC.Remove(5);
	treeC.Remove(1);
	cout << "Size of Copy: " << treeC.Size() << endl;

	//Verify order of Tree
	cout << endl << "Verify Copy Red Black Tree..." << endl;
	treeC.verify(treeC);

	cout << endl;
}
Exemplo n.º 2
0
void ConstructorTest()
{
	cout << "--------------------------Constructor Test---------------------------" << endl;

	RedBlackTree<int> tree;
	cout << "Create Tree..." << endl;
	tree.Insert(6);
	tree.Insert(7);
	tree.Insert(8);
	tree.Insert(9);
	tree.Insert(11);
	tree.Insert(2);
	tree.Insert(1);
	tree.Insert(3);
	tree.Insert(4);
	tree.Insert(5);

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

	RedBlackTree<int> treeC(tree);
	cout << "Perform Copy Tree..." << endl;
	cout << "Size of Copy: " << treeC.Size() << endl;

	//Verify order of Tree
	cout << endl << "Verify Copy Red Black Tree..." << endl;
	treeC.verify(treeC);

	cout << "Copy Blank Tree..." << endl;
	RedBlackTree<int> treeA;
	cout << "Size of Empty tree1: " << treeA.Size() << endl;
	RedBlackTree<int> treeC2(treeA);
	cout << "Size of Copy of tree1: " << treeC2.Size() << endl;

	//BST NOT RED BLACK (FOR COMPARE)!!!
	RedBlackTree<int> BST;
	BST.BSTInsert2(6);BST.BSTInsert2(7);
	BST.BSTInsert2(8);BST.BSTInsert2(9);
	BST.BSTInsert2(11);BST.BSTInsert2(2);
	BST.BSTInsert2(1);BST.BSTInsert2(3);
	BST.BSTInsert2(4);BST.BSTInsert2(5);
	cout << endl << "BST Verify..." << endl << "**NOT RED BLACK TREE**" << endl << endl;
	BST.verify(BST);

	cout << endl;
}
Exemplo n.º 3
0
void AssignmentTest()
{
	cout << "--------------------------AssignmentTest---------------------------" << endl;

	cout << endl << "Basic Tree Size of Four" << endl;
	cout  << "Insert.." << endl;
	RedBlackTree<int> tree;
	tree.Insert(5);
	tree.Insert(4);
	tree.Insert(3);
	tree.Insert(2);

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

	RedBlackTree<int> tree2;
	cout << "Assign Tree 1 to Tree 2..." << endl << endl;
	tree2 = tree;

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

	cout << "Creat Blank Tree..." << endl ;
	RedBlackTree<int> treeEmpty;
	cout << "Size: " << treeEmpty.Size() << endl << endl;

	RedBlackTree<int> tree3(tree);
	cout << "Creat Tree3 Copy of Tree1..." << endl ;
	cout << "Insert..." << endl;
	tree3.Insert(3);
	tree3.Insert(2);
	cout << "Verify Red Black Tree 3..." << endl;
	tree3.verify(tree3);

	cout << "Assign Tree3 to Empty Tree..." << endl << endl;
	cout << "Verify Red Black Tree 3..." << endl;
	tree3 = treeEmpty;
	tree3.verify(tree3);

	cout << endl;
}
RedBlackTree<T>::RedBlackTree(const RedBlackTree& rbtree) : root(NULL), size(0) {
    CopyTree(GetRoot(), rbtree.GetRoot(), rbtree.GetRoot());
    size = rbtree.Size();
}