forked from macro-0/Crouch_CSCI2270_FinalProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RedBlackTree.h
64 lines (53 loc) · 1.59 KB
/
RedBlackTree.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
#ifndef REDBLACKTREE_H
#define REDBLACKTREE_H
#include <string>
#include <vector>
struct rbNode {
std::string commonName;
std::string sciName;
std::vector<std::string> phenophase;
std::vector<int> elevation;
std::vector<int> siteID;
std::vector<std::string> date;
int count; // number of times animal/plant has an entry in database
bool isRed;
rbNode *left;
rbNode *right;
rbNode *parent;
rbNode(){};
rbNode (std::string in_commonName, std::string in_sciName, std::string in_phenophase, int in_elevation, int in_siteID, std::string in_date, int count) {
commonName = in_commonName;
sciName = in_sciName;
phenophase.push_back(in_phenophase);
elevation.push_back(in_elevation);
siteID.push_back(in_siteID);
date.push_back(in_date);
count = 0;
left = NULL;
right = NULL;
parent = NULL;
}
};
class RedBlackTree {
public:
RedBlackTree();
virtual ~RedBlackTree();
void printTree();
void addDataNode(std::string in_commonName, std::string in_sciName, std::string in_phenophase, int in_elevation, int in_siteID, std::string in_date, int count);
void findDataNode(std::string commonName);
void deleteDataNode(std::string commonName);
protected:
private:
void deleteAll(rbNode *node); // postorder
void printTree(rbNode *node);
void printNode(rbNode *node, bool lookUp);
rbNode* searchRBTree(rbNode *node, std::string commonName);
void rbAddFixup(rbNode *node);
void rbDeleteFixup(rbNode *node);
void rbTransplant(rbNode *u, rbNode *v);
void leftRotate(rbNode *x);
void rightRotate(rbNode *x);
rbNode *root;
rbNode *nil;
};
#endif // REDBLACKTREE_H