-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary_tree.cpp
46 lines (39 loc) · 1 KB
/
binary_tree.cpp
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
#include "node.hpp"
#include "binary_tree.hpp"
#include <iostream>
BinaryTree::BinaryTree()
{
BinaryTree::root = nullptr;
std::cout << "Building Object...\n" << std::endl;
}
BinaryTree::~BinaryTree()
{
std::cout << "\nDestroying Object..." << std::endl;
}
void BinaryTree::insert(int value)
{
std::cout << "Inserting " << value << "..." << std::endl;
BinaryTree::BinaryTree::root = insertRecursive(BinaryTree::root, value);
}
void BinaryTree::inOrderTraversal()
{
std::cout << "In-order traversal: " << std::endl;
inOrderRecursive(BinaryTree::root);
std::cout << std::endl;
}
void BinaryTree::preOrderTraversal()
{
std::cout << "Pre-order traversal: " << std::endl;
preOrderRecursive(BinaryTree::root);
std::cout << std::endl;
}
void BinaryTree::postOrderTraversal()
{
std::cout << "Post-order traversal: " << std::endl;
postOrderRecursive(BinaryTree::root);
std::cout << std::endl;
}
int BinaryTree::maxDepth()
{
return maxDepthRecursive(BinaryTree::root);
}