forked from FabianNorbertoEscobar/c-avanzado-ejercicios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitivas_cola_circular.c
83 lines (74 loc) · 1.32 KB
/
primitivas_cola_circular.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
82
83
#include "primitivas_cola_circular.h"
#include<stdio.h>
#include<stdlib.h>
void crear_cola(t_lista *c)
{
*c=NULL;
}
int cola_vacia(const t_lista *c)
{
return *c==NULL;
}
int cola_llena(const t_lista *c)
{
void *aux=malloc(sizeof(t_nodo));
free(aux);
return aux==NULL;
}
int acolar(t_lista *c,const t_dato *d)
{
t_nodo *nue=(t_nodo*)malloc(sizeof(t_nodo));
if(!nue)
return MEMORIA_LLENA;
nue->dato=*d;
if(!*c)
nue->sig=nue;
else
{
nue->sig=(*c)->sig;
(*c)->sig=nue;
}
*c=nue;
return OK;
}
int desacolar(t_lista *c,t_dato *d)
{
t_nodo *aux;
if(!*c)
return COLA_VACIA;
aux=(*c)->sig;
*d=aux->dato;
if(*c==aux)
*c=NULL;
else
(*c)->sig=aux->sig;
free(aux);
return OK;
}
int ver_primero_en_cola(const t_lista *c,t_dato *d)
{
if(!*c)
return COLA_VACIA;
*d=(*c)->sig->dato;
return OK;
}
int ver_ultimo_en_cola(const t_lista *c,t_dato *d)
{
if(!*c)
return COLA_VACIA;
*d=(*c)->dato;
return OK;
}
void vaciar_cola(t_lista *c)
{
t_nodo *aux,*ult=*c;
*c=(*c)->sig;
while(*c&&*c!=ult)
{
aux=*c;
*c=aux->sig;
free(aux);
}
free(*c);
*c=NULL;
}