本文整理汇总了C++中BSTree::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ BSTree::Clear方法的具体用法?C++ BSTree::Clear怎么用?C++ BSTree::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSTree
的用法示例。
在下文中一共展示了BSTree::Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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)");
//.........这里部分代码省略.........