-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVLTree.H
More file actions
executable file
·106 lines (96 loc) · 1.99 KB
/
AVLTree.H
File metadata and controls
executable file
·106 lines (96 loc) · 1.99 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
@file AVLTree.H
@brief Clase Arbol Binario Balanceado de Busqueda.
Arbol Binario Balanceado de Busqueda (AVL).
Cualquier duda o mejora informar al correo: erikvelasquez.25@gmail.com
@author Erik Velasquez
@date 8/2014
*/
#ifndef AVLTREE_H
#define AVLTREE_H
#include <iostream>
#include "BinNodeUtils.H"
/**
@class AVLTree
@brief Arbol Binario Balanceado de Busqueda
*/
template<class T> class AVLTree
{
private:
BinNode<T> *root; //cabecera o raiz del nodo
public:
/**
@brief Constructor por omision de la clase
*/
AVLTree() //inicializamos el nodo en NULL
{
root=NULL;
}
/**
@brief Obtenemos la raiz del arbol
@return puntero de la raiz BinNode<T>*
*/
BinNode<T>*& getRoot() //retornamos la raiz del arbol
{
return root;
}
/**
@brief inserto un nodo en el arbol
@param Node es el nodo a insertar
@return retorna NULL en caso de insercion fallida
*/
BinNode<T>* insert(BinNode<T>* Node)
{
if(Node == NULL)
{
throw NullNode();
}
return insertAVL(getRoot(),Node);
}
/**
@brief inserto un valor en el arbol binario
@param data es el valor a insertar
@return retorna NULL en caso de insercion fallida
*/
BinNode<T>* insert(T data)
{
BinNode<T> * node;
try
{
node = new BinNode<T>(data);
}
catch(bad_alloc &e)
{
throw NoMemory();
}
return insertAVL(getRoot(),node);
}
/**
@brief remueve un nodo en el arbol
@param key dato a ser eliminado
@return retorna NULL en caso de no remover
*/
BinNode<T>* remove(T key)
{
if(!searchAVL(getRoot(),key))
return NULL;
return removeFromAVL(getRoot(),key);//remove
}
/**
@brief busca un valor en el arbol
@param key es el dato a buscar
@return retorna NULL en caso de no encontrar el valor
*/
BinNode<T>* search(T key)
{
return searchAVL(getRoot(),key);
}
/**
@brief destructor por omision de la clase
*/
~AVLTree()
{
deleteBinNode(root);
}
};//fin clase AVLTree
#endif