-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNodoAVL.java
97 lines (93 loc) · 1.93 KB
/
NodoAVL.java
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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package eda.arbolAVL;
import eda.NodoBB;
/**
*
* @author Carla Andrea
*/
public class NodoAVL <T extends Comparable<T>>{
T elem;
NodoAVL<T> izq, der, papa;
int fe;
/*Constructor*/
NodoAVL (T elem){
this.elem=elem;
izq=null;
der=null;
papa=null;
fe=0;
}
NodoAVL(){
this.elem=null;
izq=null;
der=null;
papa=null;
fe=0;
}
//Calcula la cantidad de niveles del nodo
public int numDescendiente(){
int i=0;
if(der!=null){
i=der.numDescendiente()+1;
}
if(izq!=null){
i=izq.numDescendiente()+1+i;
}
return i;
}
public void setPapa(NodoAVL<T> papa){
this.papa=papa;
}
public void setElem(T elem) {
this.elem = elem;
}
public void setIzq(NodoAVL<T> izq) {
this.izq = izq;
}
public void setDer(NodoAVL<T> der) {
this.der = der;
}
public void setDato(T elem) {
this.elem = elem;
}
public void setFe(int fe) {
this.fe = fe;
}
public T getElem() {
return elem;
}
public int getFe() {
return fe;
}
public NodoAVL<T> getIzq() {
return izq;
}
public NodoAVL<T> getDer() {
return der;
}
public NodoAVL<T> getPapa() {
return papa;
}
public T getDato(){
return elem;
}
public void cuelga(NodoAVL<T> hijo){
if(hijo==null){
return;
}
if(hijo.getElem().compareTo(elem)<=0){
this.setIzq(hijo);
//this.izq=hijo;
}
// izq=hijo;
else{
//this.der=hijo;
this.setDer(hijo);
}
//der=hijo;
hijo.setPapa(this);
}
}