-
Notifications
You must be signed in to change notification settings - Fork 0
/
binaryTree.cc
46 lines (39 loc) · 906 Bytes
/
binaryTree.cc
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 "binaryTree.h"
template <typename T>
TreeNode<T>::TreeNode(T newValue){
this->value = newValue;
this->left = 0;
this->right = 0;
}
template <typename T>
TreeNode<T>::TreeNode(T newValue, TreeNode<T> *leftNode, TreeNode<T> *rightNode){
this->value = newValue;
this->left = leftNode;
this->right = rightNode;
}
template <typename T>
BinaryTree<T>::BinaryTree(TreeNode<T> * aNode){
this->root = aNode;
}
template <typename T>
bool BinaryTree<T>::isEmpty(){
return !this->root;
}
template<typename T>
int BinaryTree<T>::heightHelper(TreeNode<T>* aNode){
if(aNode == nullptr){
return 0;
}
else{
int leftHeight = heightHelper(aNode->left);
int rightHeight= heightHelper(aNode->right);
return leftHeight > rightHeight
? leftHeight+1
: rightHeight+1;
}
}
template <typename T>
int BinaryTree<T>::height(){
return heightHelper(this->root);
}
#include "binaryTreeConfig.h"