-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructores.cpp
More file actions
85 lines (78 loc) · 1.34 KB
/
constructores.cpp
File metadata and controls
85 lines (78 loc) · 1.34 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
85
#include <iostream>
#include "tipos.h"
#include "arbol_b.h"
#include "auxiliares.h"
int Nodo::max_llaves;
// Construccion info
Info::Info()
{
encontrado = false;
donde = NULL;
indice = -1;
}
// Destruccion info
Info::~Info()
{
donde = NULL;
}
// Construccion nodo
Nodo::Nodo()
{
cuantas_llaves = 0;
es_hoja = true;
padre = siguiente = anterior = NULL;
}
Nodo::Nodo(int o)
{
cuantas_llaves = 0;
es_hoja = true;
padre = siguiente = anterior = NULL;
max_llaves = o;
}
// Destruccion nodo
Nodo::~Nodo()
{
delete[] llaves;
if(es_hoja)
delete[] datos;
else
delete[] hijos;
padre = siguiente = anterior = NULL;
}
// Construccion arbol
void Arbol::inicializar()
{
raiz = new Nodo(orden);
raiz->llaves = new int[orden];
raiz->datos = new Registro*[orden];
principio = final = raiz;
}
Arbol::Arbol(int o)
{
orden = o;
inicializar();
}
// Destruccion arbol
void Arbol::borrar_nivel(Nodo *n)
{
Nodo *aux;
while(n){
aux = n->siguiente;
if(n->es_hoja)
eliminar_registros_en_nodo(n);
delete n;
n = aux;
}
}
Arbol::~Arbol()
{
Nodo *aux;
Nodo *n = raiz;
while(n->es_hoja == false){
aux = n->hijos[0];
borrar_nivel(n);
n = aux;
}
borrar_nivel(n);
principio = final = raiz = NULL;
}