1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include "CompleteBinaryTree.h"
using namespace std;
int main() {
cout << "Initialize Complete Binary tree \n";
CompleteBinaryTree<int> cbt;
cout << "Get height of empty tree: \n";
cbt.getHeight();
cout << "\n";
cout << "Add 0 to 16 to tree \n";
for (int i = 0; i < 16; i++) {
cbt.add(i);
}
cout << "Get height of filled tree: \n";
cbt.getHeight();
cout << "\n";
cout << "Removing 0 from tree \n";
cbt.remove(0);
cout << "Pre-order Traverse: \n";
cbt.preorderTraverse();
cout << "\n";
cout << "In-order Traverse: \n";
cbt.inorderTraverse();
cout << "\n";
cout << "Post-order Traverse: \n";
cbt.postorderTraverse();
/* do the following
1. display the height
2. add 17 numbers (from 0 to 16) to the tree
3. display the height again
4. remove the number 0
5. display the pre-order, in-order, post-order traveral of the tree
sample output:
-bash-4.1$ make test
./build/test_driver
Height: 0
Height: 5
capacity: 24
16, 1, 3, 7, 15, 8, 4, 9, 10, 2, 5, 11, 12, 6, 13, 14,
15, 7, 3, 8, 1, 9, 4, 10, 16, 11, 5, 12, 2, 13, 6, 14,
15, 7, 8, 3, 9, 10, 4, 1, 11, 12, 5, 13, 14, 6, 2, 16,
*/
return 0;
}
|