-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBTree.h
47 lines (46 loc) · 1.29 KB
/
RBTree.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
#pragma once
#include <string>
namespace leveretconey {
enum TraverseType{
PRE,IN,POST
};
enum Color
{
RED, BLACK
};
struct RBTreeNode {
Color color;
int key;
RBTreeNode *left, *right, *parent;
};
typedef RBTreeNode* RBTreeNodePointer;
class RBTree
{
private:
RBTreeNodePointer root, nil;
RBTreeNodePointer getNewNode(Color color, int key,RBTreeNodePointer parent);
void deleteNode(RBTreeNodePointer node);
void rotateLeft(RBTreeNodePointer node);
void rotateRight(RBTreeNodePointer node);
void adjustInsert(RBTreeNodePointer node);
void adjustDelete(RBTreeNodePointer node);
void traversePre(RBTreeNodePointer node, void(*callback)(RBTreeNodePointer));
void traverseIn(RBTreeNodePointer node, void(*callback)(RBTreeNodePointer));
void traversePost(RBTreeNodePointer node, void(*callback)(RBTreeNodePointer));
int getBlackHeight(RBTreeNodePointer node,bool &valid);
public:
void insert(int key);
bool isValid();
bool isEmpty();
void show();
RBTreeNodePointer getNil();
void del(int key);
void del(RBTreeNodePointer node);
RBTreeNodePointer search(int key);
RBTreeNodePointer getSuccessor(RBTreeNodePointer node);
void traverse(TraverseType type, void (*callback)(RBTreeNodePointer));
void createFromFile(std::string path);
RBTree();
~RBTree();
};
}