-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTreeT.h
More file actions
64 lines (48 loc) · 1.43 KB
/
TreeT.h
File metadata and controls
64 lines (48 loc) · 1.43 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
//
// Author: Varick Erickson
// Date: 2/18/2021
//
#ifndef TREET_H
#define TREET_H
#include <queue> // stl library
using namespace std;
// Used to identify the order you wish to traverse the tree
enum Order {POST_ORDER, IN_ORDER, PRE_ORDER};
// 0 1 2
template<class T>
class TreeT {
public:
TreeT();
~TreeT();
TreeT& operator=(const TreeT& otherTree);
void Add(T value); // Add value to the tree
void Remove(T value); // Remove value from the tree
bool Contains(T value); // Determines if value is in the tree
int Size(); // Number of value in the tree
// These are used by the iterator
void ResetIterator(Order traverseOrder); // Initializes the Iterator
T GetNextItem();
private:
struct Node {
Node* left = nullptr;
Node* right = nullptr;
T value;
};
Node* root;
int numNodes;
queue<T> printQueue;
// Used for de-constructor
void DestroyTree(Node* node);
// Used for Node removal
void RemoveHelper(Node*& subtree, T value);
void DeleteNode(Node*& subtree);
void GetPredecessor(Node* curr, T& value);
void CopyHelper(Node*& thisTree, Node* otherTree);
// Used for iterator
queue<T> iterArr; // queue used for the iterator
void PlacePreOrder(Node* node);
void PlacePostOrder(Node* node);
void PlaceInOrder(Node* node);
};
#include "TreeT.cpp"
#endif //TREET_H