-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavl.c
81 lines (75 loc) · 1.29 KB
/
avl.c
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
#include <stdio.h>
#include <stdlib.h>
typedef struct no
{
int chave, fatorb;
struct no* esquerda;
struct no* direita;
struct no* pai;
}no;
typedef struct arvore
{
no* raiz;
}arvore;
arvore* criarArvore()
{
arvore* arv= (arvore*)malloc(sizeof(arvore));
if (arv == NULL)
return NULL;
arv->raiz = NULL;
return arv;
}
no* pesquisa(arvore* arv, int chave)
{
no* aux=arv->raiz;
if (arv == NULL)
return NULL;
while(aux!=NULL)
{
if(aux->chave==chave)
{
return aux;
}
if(aux->chave>chave)
{
aux=aux->esquerda;
continue;
}
if(aux->chave<chave)
{
aux=aux->direita;
continue;
}
}
return NULL;
}
int altura(no* aux)
{
while(aux)
{
}
if(ae>ad)
{
return(ae+1);
}
else
{
return(ad+1);
}
}
no* balanceia(no* des)
{
if(des->fatorb < -1){
if(des->esquerda->fatorb > 0){
des->esquerda = rot_esquerda(des->esquerda);
}
des = rot_direita(des);
}
else if(des->fatorb > 1){
if(des->direita->fatorb < 0){
des->direita = rot_direita(des->direita);
}
des = rot_esquerda(des);
}
return des;
}