-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRooted_Tree.h
76 lines (59 loc) · 1.56 KB
/
Rooted_Tree.h
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
//
// Created by Shubi & Eyal on 21/12/2019.
//
#ifndef DALGO_ROOTED_TREE_H
#define DALGO_ROOTED_TREE_H
#include <ostream>
#include <cstddef>
#include "Tree_Node.h"
#define ZERO 0
#define ONE 1
#define CHILD 0 // Came from child
#define PARENT_SIBLING 1 // Came from parent or left sibling
/*
* Implementation of a LCRS Rooted tree
*
* supports Print_By_Layer() and Preorder_Print()
*/
class Rooted_Tree {
public:
/*
* Default Constructor
*/
Rooted_Tree() : _root(NULL),_number_of_nodes_in_tree(ZERO) {}
/*
* Constructor with a given root
*/
Rooted_Tree(Tree_Node *root) : _root(root),_number_of_nodes_in_tree(ONE) {}
/*
* Destructor
* Deletes the tree and any data stored in it
*/
~Rooted_Tree() {
// the root then deletes left child &
// right sibling which in turn delete their child and sibling and so on
delete _root;
}
/*
* Prints the key of each node according to defined procedure
*/
void Print_By_Layer(std::ostream& stream) const;
/*
* Prints the key of each node according to Preorder order
*/
void Preorder_Print(std::ostream& stream) const;
/*
* Setter
*/
void setNumberOfNodesInTree(unsigned int numberOfNodesInTree);
/*
* Increment number of nodes in tree
*/
void incrementNumberOfNodesInTree(){
_number_of_nodes_in_tree++;
}
private:
Tree_Node* _root; // pointer to tree root
unsigned _number_of_nodes_in_tree; // Stores the number of nodes in the tree
};
#endif //DALGO_ROOTED_TREE_H