-
Notifications
You must be signed in to change notification settings - Fork 0
/
BinaryTreeNode.cpp
executable file
·90 lines (88 loc) · 1.54 KB
/
BinaryTreeNode.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <cstddef>
#include <iostream>
#include <stdexcept>
template <typename DataType>
class Node {
public:
Node(DataType startingValue) {
leftChild = NULL;
rightChild = NULL;
value = startingValue;
}
void setValue (DataType newValue) {
value = newValue;
;
}
void setLeft (Node<DataType>* newLeft) {
leftChild = newLeft;
;
}
void setRight (Node<DataType>* newRight) {
rightChild = newRight;
;
}
DataType getValue() {
return value;
;
}
Node<DataType>* getLeft() {
return leftChild;
;
}
Node<DataType>* getRight() {
return rightChild;
;
}
void operator= (const Node<DataType> &assignee) {
value = assignee->getValue();
;
}
private:
Node<DataType>* leftChild;
Node<DataType>* rightChild;
DataType value;
};
template <typename DataType>
class BinaryTree {
public:
BinaryTree() {
root = NULL;
sizee = 0;
levelOrderTraverse = NULL;
inOrderTraverse = NULL;
}
void addLeftChild(DataType* Node, DataType newValue) {
Node.setLeft(Node(newValue));
;
}
void addRightChild(DataType* Node, DataType newValue) {
Node.setRight(Node(newValue));
;
}
Node<DataType>* root() {
retrun root;
;
}
bool isEmpty() {
return ((sizee==0)?true:false);
;
}
int size() {
return sizee;
;
}
void postOrderTraverse(Node<DataType>* curr) {
if (curr == NULL) {
return;
}
postOrderTraverse(curr->getLeft());
postOrderTraverse(curr->getRight());
cout << curr->getValue() << " ";
return;
}
private:
Node<DataType>* root;
int sizee, curr;
DataType* levelOrderTraverse;
DataType* inOrderTraverse;
};