-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack_List.c
47 lines (40 loc) · 906 Bytes
/
Stack_List.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
#include "Stack_list.h"
#include <stdlib.h>
#include <assert.h>
int StacklistPush(Stack_t_l *ps, int e)
{
List_t aux;
aux=ps->top;
ps->top=__ListNodeCreate(e,NULL);
ps->top->pNext=aux;
ps->size++;
return 1;
}
int StacklistPop(Stack_t_l *ps, int *pe)
{
List_t aux;
if(ps->top==NULL)
{
return 0;
}
*pe=ps->top->cont;
aux=ps->top->pNext;
free(ps->top);
ps->top=aux;
ps->size--;
return 1;
}
Stack_t_l * StacklistCreate(void) //Una de la ventajas con lista es que el tamaño es dinamico
{
Stack_t_l *ns = (Stack_t_l *) malloc(sizeof(Stack_t_l));
assert(ns != NULL);
ns->size = 0;
ns->top = NULL;
//ns->pElements = (int *) malloc(size * sizeof(int));
//assert(ns->pElements);
return ns;
}
int StacklistIsEmpty(Stack_t_l *ps)
{
return ps->top == NULL;
}