-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpila.c
53 lines (48 loc) · 994 Bytes
/
pila.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
#include "pila.h"
#include <malloc.h>
#include <memory.h>
void P_Crear(TPila *pP, int TamanioDato)
{
pP->Tope = NULL;
pP->TamanioDato = TamanioDato;
}
void P_Vaciar(TPila *pP)
{
TNodoPila *pAux = pP->Tope;
TNodoPila *pSig;
while (pAux)
{
pSig = pAux->Siguiente;
free(pAux->Elem);
free(pAux);
pAux = pSig;
}
pP->Tope= NULL;
}
int P_Vacia(TPila P)
{
return (P.Tope==NULL);
}
int P_Agregar(TPila *pP, void* pE)
{
TNodoPila *pNodo = (TNodoPila*) malloc(sizeof(TNodoPila));
if (!pNodo)
return FALSE;
else
{
pNodo->Siguiente = pP->Tope;
pP->Tope = pNodo;
pNodo->Elem = malloc (pP->TamanioDato);
memcpy(pNodo->Elem, pE, pP->TamanioDato);
return TRUE;
}
}
int P_Sacar(TPila *pP, void* pE)
{
TNodoPila *pAux = pP->Tope;
pP->Tope = pP->Tope->Siguiente;
memcpy(pE, pAux->Elem, pP->TamanioDato);
free(pAux->Elem);
free(pAux);
return TRUE;
}