-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.cpp
More file actions
84 lines (71 loc) · 1.67 KB
/
node.cpp
File metadata and controls
84 lines (71 loc) · 1.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "node.h"
#include <cstddef>
BTNode::BTNode(std::string cID, BTNode* par = NULL) {
sizee = 0;
//parentIndex = -1;
for (int i = 0; i < CHILD_MAX; ++i) {
keys[i] = NULL;
children[i] = NULL;
}
columnName = cID;
parent = par;
}
void BTNode::addNodeByIndex(Node* newNode, int posID = 0) {
// ADDS A NODE SOLELY IN BTNode AND NOT THE CHILDREN
for (int i = CHILD_MAX; i > posID; --i) {
keys[i] = keys[i-1];
children[i] = children[i-1];
}
keys[posID] = newNode;
sizee++;
return;
}
int BTNode::addNode(Node* newNode) {
for (int i = 0; i < sizee; ++i) {
if (keys[i]->data >= newNode->data) {
addNodeByIndex(newNode, i);
return i;
}
}
addNodeByIndex(newNode, sizee);
return sizee-1;
}
void BTNode::delNode(int posID = 0) {
// DELETES A NODE SOLELY IN BTNode AND NOT THE CHILDREN
for (int i = posID; i <= CHILD_MAX; ++i) {
keys[i] = keys[i+1];
children[i] = children[i+1];
}
sizee--;
return;
}
int BTNode::size() {
return sizee;
}
//int BTNode::index() {
// return parentIndex;
//}
//void BTNode::setParentIndex(int newIndex) {
// parentIndex = newIndex;
//}
Node* BTNode::getKey(int posID = 0) {
return keys[posID];
}
BTNode* BTNode::getChild(int posID = 0) {
return children[posID];
}
BTNode* BTNode::getParent() {
return parent;
}
void BTNode::setChild(BTNode* newChild, int posID) {
children[posID] = newChild;
return;
}
void BTNode::setParent(BTNode* newParent) {
parent = newParent;
return;
}
void BTNode::setKey(Node* newKey, int posID = 0) {
keys[posID] = newKey;
return;
}