示例#1
0
文件: test.cpp 项目: nihy/cse274b
bool TestPartThree() {
  BinarySearchTree<BSTNode1<int>, int> tree;
  tree.add(15);
  tree.add(10);
  tree.add(14);
  tree.add(17);
  tree.add(20);
  tree.add(16);
  tree.add(19);
  tree.add(26);
  tree.add(7);
  tree.add(9);
  tree.add(5);

  tree.preOrderNumber();
  tree.inOrderNumber();
  tree.postOrderNumbers();

  bool testPreOrder, testInOrder, testPostOrder;
  if ((tree.getNode(15)->pre_order == 1) && (tree.getNode(5)->pre_order == 4)
      && (tree.getNode(26)->pre_order == 11))
    testPreOrder = true;
  if ((tree.getNode(15)->in_order == 6) && (tree.getNode(5)->in_order == 1)
        && (tree.getNode(26)->in_order == 11))
      testInOrder = true;
  if ((tree.getNode(15)->pst_order == 11) && (tree.getNode(5)->pst_order == 1)
        && (tree.getNode(26)->pst_order == 8))
      testPostOrder = true;

  return testPreOrder && testInOrder && testPostOrder;
}
示例#2
0
文件: test.cpp 项目: natemara/CSE-274
void TestBinarySearchTreeInOrder() {
  BinarySearchTree<BSTNode1<int>, int> b;

  b.add(4);
  b.add(2);
  b.add(5);
  b.add(1);
  b.add(3);
  b.add(6);

  b.inOrderNumber();

  assert(b.getNode(1)->in_order_ == 0);
  assert(b.getNode(2)->in_order_ == 1);
  assert(b.getNode(3)->in_order_ == 2);
  assert(b.getNode(4)->in_order_ == 3);
  assert(b.getNode(5)->in_order_ == 4);
  assert(b.getNode(6)->in_order_ == 5);
}
示例#3
0
void testPart3(){
	BinarySearchTree<BSTNode1<int>, int> tree = treeMaker(1);
	BinarySearchTree<BSTNode1<int>, int> tree2 = treeMaker(2);
	tree.preOrderNumber();
	cout << tree.getNode(10)->pre_number << endl;
	cout << tree.getNode(15)->pre_number << endl;
	cout << tree.getNode(2)->pre_number << endl << endl;

	tree.inOrderNumber();
	cout << tree.getNode(10)->in_number << endl;
	cout << tree.getNode(15)->in_number << endl;
	cout << tree.getNode(2)->in_number << endl << endl;

	tree.postOrderNumber();
	cout << tree.getNode(10)->post_number << endl;
	cout << tree.getNode(15)->post_number << endl;
	cout << tree.getNode(2)->post_number << endl << endl;

	tree2.preOrderNumber();
	cout << tree2.getNode(20)->pre_number << endl;
	cout << tree2.getNode(5)->pre_number << endl;
	cout << tree2.getNode(35)->pre_number << endl;
	cout << tree2.getNode(10)->pre_number << endl;
	cout << tree2.getNode(30)->pre_number << endl << endl;

	tree2.inOrderNumber();
	cout << tree2.getNode(20)->in_number << endl;
	cout << tree2.getNode(5)->in_number << endl;
	cout << tree2.getNode(35)->in_number << endl;
	cout << tree2.getNode(10)->in_number << endl;
	cout << tree2.getNode(30)->in_number << endl << endl;

	tree2.postOrderNumber();
	cout << tree2.getNode(20)->post_number << endl;
	cout << tree2.getNode(5)->post_number << endl;
	cout << tree2.getNode(35)->post_number << endl;
	cout << tree2.getNode(10)->post_number << endl;
	cout << tree2.getNode(30)->post_number << endl << "END3" << endl;
}
示例#4
0
文件: test.cpp 项目: rakhlei/cse274b
void testPart3() {
	cout << "Part 3" << endl;
	BinarySearchTree<BSTNode1<int>, int> tree;
	tree.add(15);
	tree.add(5);
	tree.add(3);
	tree.add(12);
	tree.add(10);
	tree.add(6);
	tree.add(7);
	tree.add(13);
	tree.add(16);
	tree.add(20);
	tree.add(18);
	tree.add(23);
	cout << "pre order: " << endl;
	tree.preOrderNumber();
	cout << endl;
	cout << "in order: " << endl;
	tree.inOrderNumber();
	cout << "post order: " << endl;
	tree.postOrderNumber();

}