-
Notifications
You must be signed in to change notification settings - Fork 0
/
BPTREE.h
56 lines (45 loc) · 1.57 KB
/
BPTREE.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
#ifndef BPTREE_H_INCLUDED
#define BPTREE_H_INCLUDED
#include <string>
using namespace std;
class Bplustree
{
//this is a 4-5 tree
const static int Max_Number_Of_Branches=5;
private:
Bplustree *branch[Max_Number_Of_Branches]; //for storing branches
int key[Max_Number_Of_Branches-1]; //for storing the key in the node
int keyNumNow; //the number of key in the node now
//pointer to the right sibling
//have to do some converting
//when one node is creating
//and is connected to other nodes
Bplustree *Sequential_Next;
//the father of the node
//have to do some converting when the one branch is moved from one node to another
//otherwise it will lead to some error
Bplustree *father;
bool leaf;//whether the node if leaf or not
void Refresh(int x,Bplustree *p);
void InsertIndex(Bplustree *p,int x,Bplustree *s,Bplustree *q,Bplustree *&root);
void DeleteIndex(Bplustree *p,int k,Bplustree *&root);
public:
Bplustree(){
for (int i=0;i<Max_Number_Of_Branches;i++)
this->branch[i]=NULL;
for (int i=0;i<Max_Number_Of_Branches-1;i++)
this->key[i]=0;
this->keyNumNow=0;
this->father=NULL;
this->Sequential_Next=NULL;
this->leaf=true;
}
~Bplustree(){
}
static Bplustree *FindLeaf(int x,Bplustree *root);
int Insert(int x,Bplustree *&root);
bool Search(int x,Bplustree *root);
void Delete(int x,Bplustree *&root);
void print(Bplustree* root);
};
#endif // BPTREE_H_INCLUDED