forked from FabianNorbertoEscobar/c-avanzado-ejercicios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitivas_cola_estática.c
63 lines (55 loc) · 1.05 KB
/
primitivas_cola_estática.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
#include "primitivas_cola_estática.h"
void crear_cola(t_cola *c)
{
c->pri=0;
c->ult=-1;
}
int cola_llena(const t_cola *c)
{
return (c->ult+1)%TAM==c->pri&&c->ult!=-1;
}
int acolar(t_cola *c,const t_dato *d)
{
if((c->ult+1)%TAM==c->pri&&c->ult!=-1)
return COLA_LLENA;
c->ult=(c->ult+1)%TAM;
c->cola[c->ult]=*d;
return OK;
}
int cola_vacia(const t_cola *c)
{
return c->ult==-1;
}
int desacolar(t_cola *c,t_dato *d)
{
if(c->ult==-1)
return COLA_VACIA;
*d=c->cola[c->pri];
if(c->pri==c->ult)
{
c->pri=0;
c->ult=-1;
}
else
c->pri=(c->pri+1)%TAM;
return OK;
}
int ver_primero_en_cola(const t_cola *c,t_dato *d)
{
if(c->ult==-1)
return COLA_VACIA;
*d=c->cola[c->pri];
return OK;
}
int ver_ultimo_en_cola(const t_cola *c,t_dato *d)
{
if(c->ult==-1)
return COLA_VACIA;
*d=c->cola[c->ult];
return OK;
}
void vaciar_cola(t_cola *c)
{
c->pri=0;
c->ult=-1;
}