-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin_tree.h
More file actions
70 lines (63 loc) · 2.54 KB
/
bin_tree.h
File metadata and controls
70 lines (63 loc) · 2.54 KB
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
#ifndef BIN_TREE_H
#define BIN_TREE_H
namespace bin_tree_node{
template<class T>
struct Node{
Node(T data=static_cast<T>(0), struct Node<T> *lchild=NULL, struct Node<T> *rchild=NULL);
struct Node<T>* lchild;
T data;
struct Node<T>* rchild;
};
}
template<class T>
class BinTree{
private:
struct bin_tree_node::Node<T> *root;
int nodeCount;
void preorder(T* pre, bin_tree_node::Node<T> *root) const;
int preorderAndCount(T* pre, bin_tree_node::Node<T> *root) const;
void inorder(T* in, bin_tree_node::Node<T> *root) const;
int inorderAndCount(T* in, bin_tree_node::Node<T> *root) const;
void postorder(T* post, bin_tree_node::Node<T> *root) const;
int postorderAndCount(T* post, bin_tree_node::Node<T> *root) const;
void levelorder(T* level, bin_tree_node::Node<T> *root) const;
int levelorderAndCount(T* level, bin_tree_node::Node<T> *root) const;
public:
// Constructors
BinTree();
BinTree(T root_val);
BinTree(bin_tree_node::Node<T> *root);
BinTree(BinTree<T>& bin_tree);
// Accessors (Getter Functions)
T* preorder() const;
T* preorder(bin_tree_node::Node<T>* root) const;
T* inorder() const;
T* inorder(bin_tree_node::Node<T>* root) const;
T* postorder() const;
T* postorder(bin_tree_node::Node<T>* root) const;
T* levelorder() const;
T* levelorder(bin_tree_node::Node<T>* root) const;
bin_tree_node::Node<T>* getRootNode() const;
int height() const;
int height(bin_tree_node::Node<T> *root) const;
int nodesCount() const;
int nodesCount(bin_tree_node::Node<T> *root) const;
// Mutators (Setter Functions)
void createTreeFromUserInput();
void destroyCurrentBinaryTree();
void destroyCurrentBinaryTree(bin_tree_node::Node<T>* root);
// Facilitators
void displayAsPreorder() const;
void displayAsPreorder(bin_tree_node::Node<T>* root) const;
void displayAsPostorder() const;
void displayAsPostorder(bin_tree_node::Node<T>* root) const;
void displayAsInorder() const;
void displayAsInorder(bin_tree_node::Node<T>* root) const;
void displayAsLevelorder() const;
void displayAsLevelorder(bin_tree_node::Node<T>* root) const;
// Enquiry Functions
bool isEmpty() const;
// Destructor
~BinTree();
};
#endif