Esempio n. 1
0
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;
}
Esempio n. 2
0
void TestBinaryTreeHeight2() {
  BinarySearchTree<BSTNode1<int>, int> b;
  int test = 0;

  for (int i = 0; i < 10000; i++) {
    test = rand() % 100000;
    b.add(test);
  }

  assert(b.height() - b.depth(b.getNode(test)) == b.height2(b.getNode(test)));
  assert(b.height2(b.getRoot()) == b.height());
}
Esempio n. 3
0
void TestBinarySearchTreePostOrder() {
  BinarySearchTree<BSTNode1<int>, int> b;

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

  b.postOrderNumbers();

  assert(b.getNode(1)->post_order_ == 0);
  assert(b.getNode(3)->post_order_ == 1);
  assert(b.getNode(2)->post_order_ == 2);
  assert(b.getNode(6)->post_order_ == 3);
  assert(b.getNode(5)->post_order_ == 4);
  assert(b.getNode(4)->post_order_ == 5);
}
Esempio n. 4
0
void testPart1(){
	BinarySearchTree<BSTNode1<int>, int> tree = treeMaker(1);
	BSTNode1<int>* node = tree.getNode(10);
	cout << tree.size() << endl;
	cout << tree.height() << endl;
	cout << tree.height2(node) << endl << endl;
	BinarySearchTree<BSTNode1<int>, int> tree2 = treeMaker(2);
	BSTNode1<int>* node2 = tree2.getNode(20);
	cout << tree2.size() << endl;
	cout << tree2.height() << endl;
	cout << tree2.height2(node2) << endl << "END1" << endl;
}
Esempio n. 5
0
void testPart1() {
	cout << "Part 1" << endl;
	BinarySearchTree<BSTNode1<int>, int> tree;
	tree.add(15);
	tree.add(5);
	tree.add(16);
	tree.add(3);
	tree.add(12);
	tree.add(10);
	tree.add(13);
	tree.add(6);
	tree.add(7);
	tree.add(20);
	tree.add(18);
	tree.add(23);

	cout << "height of node: " << tree.height2(tree.getNode(5)) << endl;
	cout << "height of tree: " << tree.height() << endl;
	cout << endl;
}
Esempio n. 6
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;
}