-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfila.c
More file actions
64 lines (48 loc) · 992 Bytes
/
fila.c
File metadata and controls
64 lines (48 loc) · 992 Bytes
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
#include "fila.h"
Fila* criar_fila() {
Fila* f = calloc(1, sizeof(Fila));
return f;
}
void insere_fim(Fila* f, Arvore* a) {
a->prox = NULL;
if(f->inicio == NULL){
f->inicio = a;
}
else{
f->final->prox = a;
}
f->final = a;
f->tam += 1;
}
int vazia_fila(Fila *f) {
if(f->inicio == NULL || f->tam <= 0) return 1;
else return 0;
}
Arvore* retirar_fila(Fila *f) {
Arvore *aux;
if(f->inicio != NULL){
aux = f->inicio;
f->inicio = f->inicio->prox;
f->tam -= 1;
}
return aux;
}
void imprimir_largura(Arvore* a) {
if(a == NULL) return;
Fila* f = calloc(1, sizeof(Fila));
Arvore* b;
insere_fim(f, a);
printf("%d ", a->valor);
while(!vazia_fila(f)){
b = retirar_fila(f);
if(b->esq != NULL){
insere_fim(f, b->esq);
printf("%d ", b->esq->valor);
}
if(b->dir != NULL) {
insere_fim(f, b->dir);
printf("%d ", b->dir->valor);
}
}
return;
}