forked from krishna14kant/Data-Structures-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
58 lines (50 loc) · 732 Bytes
/
Copy pathqueue.c
File metadata and controls
58 lines (50 loc) · 732 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
#include <stdio.h>
#define max 100
typedef struct
{
int n;
int inicio;
int vet[max];
} fila;
fila *cria_fila()
{
fila *f = (fila *)malloc(sizeof(fila));
f->inicio = 0;
f->n = 0;
return f;
}
int insere(fila *f, int v)
{
int fim = 0;
if (f->n < max)
{
fim = (f->inicio + f->n) % max;
f->vet[fim] = v;
f->n++;
return 1;
}
return 0;
}
int retira(fila *f)
{
int ret;
if (f->n > 0)
{
ret = f->vet[f->inicio];
f->inicio = ((f->inicio) + 1) % max;
f->n--;
}
return ret;
}
int size(fila *f)
{
return f->n;
}
int is_empty(fila *f)
{
return f->n == 0;
}
int is_full(fila *f)
{
return f->n == max;
}