-
Notifications
You must be signed in to change notification settings - Fork 1
/
AVL.hpp
55 lines (46 loc) · 1.44 KB
/
AVL.hpp
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Wilsen Hernandez. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
#ifndef _AVL_TREE_HPP__
#define _AVL_TREE_HPP__
#include <iostream>
#include <cstdlib>
#include "BST.hpp"
template<class T>
class AVL : public BST<T>
{
public:
AVL() : BST<T>() { };
AVL(T e) : BST<T>(e) { };
AVL(NodeBT<T>* p) : BST<T>(p) { };
AVL(const AVL<T>& t) : BST<T>(t) { }
AVL(Lista<T> p, Lista<T> in, Traverse t) : BST<T>(p, in, t) { };
void insert(T);
void del(T);
private:
NodeBT<T>* insert(T, NodeBT<T>*);
};
template<class T>
void AVL<T>::insert(T e)
{
this->_root = insert(e, this->_root);
}
// =====================================================================
template<class T>
NodeBT<T>* AVL<T>::insert(T e, NodeBT<T> *p)
{
if (p == NULL) return new NodeBT<T>(e);
if (e < p->getKey())
p->setLeft(insert(e, p->getLeft()));
else if (e > p->getKey())
p->setRight(insert(e, p->getRight()));
else
p->setKey(e);
if (abs(p->getLeft()->height() - p->getRight()->height()) > 1)
{
std::cout << "test" << std::endl;
}
return p;
}
#endif