forked from FabianNorbertoEscobar/c-avanzado-ejercicios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitivas_pila_dinámica.c
63 lines (55 loc) · 1.05 KB
/
primitivas_pila_dinámica.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_pila_dinámica.h"
//no sé por qué si no pongo las bibliotecas acá me tira error
#include<stdio.h>
#include<stdlib.h>
void crear_pila(t_pila *p)
{
*p=NULL;
}
int pila_llena(const t_pila *p)
{
void *aux=malloc(sizeof(t_nodo));
free(aux);
return aux==NULL;
}
int apilar(t_pila *p,const t_dato *d)
{
t_nodo *nuevo=(t_nodo*)malloc(sizeof(t_nodo));
if(!nuevo)
return MEMORIA_LLENA;
nuevo->dato=*d;
nuevo->sig=*p;
*p=nuevo;
return OK;
}
int pila_vacia(const t_pila *p)
{
return *p==NULL;
}
int desapilar(t_pila *p,t_dato *d)
{
if(*p==NULL)
return PILA_VACIA;
t_nodo *aux=*p;
*d=(*p)->dato;//*d=aux->dato;
*p=aux->sig;//*p=(*p)->sig;
free(aux);
return OK;
}
int ver_tope(const t_pila *p,t_dato *d)
{
if(*p==NULL)
return PILA_VACIA;
*d=(*p)->dato;
return OK;
}
void vaciar_pila(t_pila *p)
{
t_nodo *aux;
while(*p)
{
aux=*p;
*p=aux->sig;
free(aux);
}
}