-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-3-4_B_Tree.h
99 lines (77 loc) · 2 KB
/
2-3-4_B_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 2-3-4_B_Tree.h
// Brian Keppinger
#pragma once
class DataItem
{
public:
// should the data be private?
long data;
// Default constructor
DataItem(void);
// Default destructor
~DataItem(void);
void DisplayItem();
// void DestroyDI();
private:
// void DestroyDataItem(DataItem* &dataItemPointer);
};
class TwoThreeFourNode
{
public:
// Default constructor
TwoThreeFourNode(void);
// Default destructor
~TwoThreeFourNode(void);
void ConnectChild(int childNum, TwoThreeFourNode* child);
TwoThreeFourNode* DisconnectChild(int childNum);
TwoThreeFourNode* GetChild(int childNum);
TwoThreeFourNode* GetParent();
int InsertItem(DataItem* newItem);
DataItem* RemoveItem();
int GetNumItems();
int FindItem(long key);
int FindIndex(long key);
void DisplayNode();
bool b_IsLeaf();
bool b_IsFull();
void Remove(long key);
void RemoveFromLeaf(int index);
void RemoveFromNonLeaf(int index);
void BorrowFromPrevious(int index);
void BorrowFromNext(int index);
void Merge(int index);
void Fill(int index);
int GetPredecessor(int index);
int GetSuccessor(int index);
int FindKey(int key);
DataItem* GetItem(int index);
private:
static const int ORDER = 4;
int numItems;
TwoThreeFourNode* parent;
DataItem* dataItemArray[ORDER - 1];
TwoThreeFourNode* childArray[ORDER];
};
class Tree234
{
public:
// Default constructor
Tree234(void);
// Default destructor
~Tree234(void);
int Find(long key);
void Insert(long dataValue);
void Split(TwoThreeFourNode* inNode);
TwoThreeFourNode* GetNextChild(TwoThreeFourNode* inNode, long inValue);
bool IsEmpty();
void DisplayPreOrder();
void DisplayInOrder();
void DisplayPostOrder();
void RemoveFromTree(long key);
private:
// Recursive PreOrder Traversal
void RecursivePreOrderTraversal(TwoThreeFourNode* inNode, int level, int childNumber);
void RecursiveInOrderTraversal(TwoThreeFourNode* inNode, int level, int childNumber);
void RecursivePostOrderTraversal(TwoThreeFourNode* inNode, int level, int childNumber);
TwoThreeFourNode* root;
};