当前位置: 首页>>代码示例>>C++>>正文


C++ BSTree::InOrder方法代码示例

本文整理汇总了C++中BSTree::InOrder方法的典型用法代码示例。如果您正苦于以下问题:C++ BSTree::InOrder方法的具体用法?C++ BSTree::InOrder怎么用?C++ BSTree::InOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BSTree的用法示例。


在下文中一共展示了BSTree::InOrder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
	BSTree<int,int> bst;
	bst.Insert_NR(1, 1);
	bst.Insert_NR(2, 2);
	bst.Insert_NR(3, 3);
	bst.Insert_NR(4, 4);
	bst.Insert_NR(6, 6);
	bst.InOrder();
	
	bst.Delete_NR(6);
	bst.Delete_NR(2);
	bst.Delete_NR(3);
	bst.Delete_NR(4);
	bst.InOrder();
	

	bst.Insert_R(1, 1);
	bst.Insert_R(2, 2);
	bst.Insert_R(3, 3);
	bst.Insert_R(4, 4);
	bst.Insert_R(6, 6);
	bst.InOrder();
	
	bst.Delete_R(6);
	bst.Delete_R(2);
	bst.Delete_R(3);
	bst.Delete_R(4);
	bst.InOrder();
	
	return 0;
}
开发者ID:lihuanhuan1314,项目名称:Datastructure,代码行数:32,代码来源:Test.cpp

示例2: main

int main(int args,char* argv[]){


	BSTree * myTree = new BSTree;
	myTree->Insert(80);
	myTree->Insert(43);
	myTree->Insert(21);
	myTree->Insert(42);
	myTree->Insert(20);
	myTree->Insert(50);
	myTree->Insert(6);
	myTree->Insert(74);
	myTree->Insert(12);
	myTree->Insert(78);
	myTree->Insert(52);

	myTree->InOrder();
	cout << endl;
	myTree->PostOrder();
	cout << endl;
	myTree->PreOrder();
	cin.get();
	return 0;
}
开发者ID:ManosAgelidis,项目名称:BinarySearchTree,代码行数:24,代码来源:main.cpp

示例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)");
//.........这里部分代码省略.........
开发者ID:burkell530,项目名称:Repository321,代码行数:101,代码来源:exercise_25.cpp


注:本文中的BSTree::InOrder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。