-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpila.c
47 lines (42 loc) · 777 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
#include"pila.h"
struct Stack *
Push (struct Stack *stack, int data)
{
struct Stack *new = NULL;
new = (struct Stack *) malloc (sizeof (struct Stack));
new->data = data;
if(stack == NULL)
{
new -> next = NULL;
}
else
{
new -> next = stack;
}
return new;
}
struct Stack *
Pop (struct Stack *stack)
{
struct Stack *aux = stack;
stack = stack->next;
free (aux);
return stack;
}
struct Stack *PrintStack(struct Stack *stack)
{
struct Stack *new_stack = NULL;
struct Stack *aux = stack;
while(aux != NULL)
{
printf("%d\n",aux -> data);
new_stack = Push(new_stack,aux -> data);
aux = Pop(aux);
}
while(new_stack != NULL)
{
aux = Push(aux,new_stack -> data);
new_stack = Pop(new_stack);
}
return aux;
}