-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtreea.h
55 lines (49 loc) · 1.08 KB
/
btreea.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
#ifndef BTREEA_H
#define BTREEA_H
#include "node.h"
#include <iostream>
using namespace std;
class BTreea
{
Node *root;
int degree;
public:
BTreea(int size)
{
root = NULL;
degree = size;
}
Node* search(int k)
{
if(!root)
throw "No se encontró";
else
return root->search(k);
}
void insert(int k)
{
if (root == NULL)
{
root = new Node(degree, true);
root->keys[0] = k;
root->n = 1;
}
else
{
if (root->n == 2*degree-1)
{
Node * new_node = new Node(degree, false);
new_node->child[0] = root;
new_node->splitChild(0, root);
int i = 0;
if (new_node->keys[0] < k)
i++;
new_node->child[i]->insertNonFull(k);
root = new_node;
}
else
root->insertNonFull(k);
}
}
};
#endif