本文整理汇总了C++中BSTree::Remove方法的典型用法代码示例。如果您正苦于以下问题:C++ BSTree::Remove方法的具体用法?C++ BSTree::Remove怎么用?C++ BSTree::Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSTree
的用法示例。
在下文中一共展示了BSTree::Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestBSTree
void TestBSTree()
{
// 5 3 4 1 7 8 2 6 0 9
BSTree<int, double> t;
t.Insert(5,5);
t.Insert(3,3);
t.Insert(4,4);
t.Insert(1,1);
t.Insert(7,7);
t.Insert(8,8);
t.Insert(2,2);
t.Insert(6,6);
t.Insert(0,0);
t.Insert(9,9);
t.PrevOrder();
BSTNode<int,double>* ret = t.Find(9);
cout<<"Find 9 ?: "<<ret->_key<<endl;
ret = t.Find(10);
cout<<"Find 10 ?: "<<ret<<endl;
t.Remove(8);
t.Remove(1);
t.Remove(5);
t.PrevOrder();
}
示例2: Test1
void Test1()
{
int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
BSTree<int, int> bst;
for (int i = 0; i < (sizeof(a) / sizeof(a[0])); ++i)
{
bst.Insert(a[i], i);
}
bst.Inorder();
//cout << bst.Find(10)->_key << endl;
cout << "------------------------------------------" << endl;
cout<<bst.Remove(8)<<endl;
bst.Inorder();
}
示例3: UnitTest
// For testing (DO NOT ALTER)
void UnitTest() {
string temp = "This unit test will test some of your code:\n";
cout << temp << string(temp.length() - 1, '-') << endl;
cout << "Total Number of Tests: 67" << endl;
// Tests
BSTree tree;
string actual = "";
Test(tree.Remove(1) == false, "Default Constructor / Remove(1)");
Test(
tree.Insert(50) == true && tree.Insert(50) == false
&& tree.Insert(25) == true && tree.Insert(25) == false
&& tree.Insert(75) == true && tree.Insert(75) == false
&& tree.Insert(30) == true && tree.Insert(30) == false
&& tree.Insert(29) == true && tree.Insert(29) == false
&& tree.Insert(31) == true && tree.Insert(31) == false
&& tree.Insert(32) == true && tree.Insert(32) == false
&& tree.Insert(33) == true && tree.Insert(33) == false
&& tree.Insert(34) == true && tree.Insert(34) == false,
"Insert Stress Test");
Test(tree.GetSize() == 9, "GetSize()");
actual = "25 29 30 31 32 33 34 50 75 ";
Test(tree.FindMin() == 25, "FindMin()");
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
tree.Clear();
Test(tree.GetSize() == 0, "Clear() / GetSize()");
Test(tree.FindMin() == 0, "FindMin()");
Test(tree.Insert(10) == true, "Insert(10)");
Test(tree.GetSize() == 1, "GetSize()");
actual = "10 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Remove(10) == true, "Remove(10)");
Test(tree.GetSize() == 0, "GetSize()");
actual = "";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(
tree.Insert(10) == true && tree.Insert(5) == true
&& tree.Insert(15) == true,
"Insert(10), Insert(5), Insert(15)");
Test(tree.GetSize() == 3, "GetSize()");
Test(tree.FindMin() == 5, "FindMin()");
actual = "5 10 15 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Remove(1) == false, "Remove(1)");
Test(tree.Remove(5) == true, "Remove(5)");
Test(tree.GetSize() == 2, "GetSize()");
Test(tree.FindMin() == 10, "FindMin()");
actual = "10 15 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Insert(5) == true, "Insert(5)");
Test(tree.GetSize() == 3, "GetSize()");
Test(tree.FindMin() == 5, "FindMin()");
actual = "5 10 15 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Remove(15) == true, "Remove(15)");
Test(tree.GetSize() == 2, "GetSize()");
Test(tree.FindMin() == 5, "FindMin()");
actual = "5 10 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Insert(15) == true, "Insert(15)");
Test(tree.GetSize() == 3, "GetSize()");
Test(tree.FindMin() == 5, "FindMin()");
actual = "5 10 15 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Remove(10) == true, "Remove(10)");
Test(tree.GetSize() == 2, "GetSize()");
Test(tree.FindMin() == 5, "FindMin()");
actual = "5 15 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Insert(3) == true, "Insert(3)");
Test(tree.GetSize() == 3, "GetSize()");
Test(tree.FindMin() == 3, "FindMin()");
actual = "3 5 15 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Remove(15) == true, "Remove(15)");
Test(tree.GetSize() == 2, "GetSize()");
Test(tree.FindMin() == 3, "FindMin()");
actual = "3 5 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Insert(10) == true, "Insert(10)");
Test(tree.GetSize() == 3, "GetSize()");
Test(tree.FindMin() == 3, "FindMin()");
actual = "3 5 10 ";
Test(tree.InOrder() == actual, "InOrder()", tree.InOrder(), actual);
Test(tree.Remove(1) == false, "Remove(1)");
Test(tree.Remove(100) == false, "Remove(100)");
//.........这里部分代码省略.........