-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
45 lines (43 loc) · 750 Bytes
/
Copy pathstack.c
File metadata and controls
45 lines (43 loc) · 750 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
void create(stack *s)
{
s->top = NULL;
}
int push(stack *s, int data)
{
struct node *aux;
aux = (struct node *) malloc(sizeof(struct node));
if(aux == NULL)
return FALSE;
aux->data = data;
aux->next = s->top;
s->top = aux;
return TRUE;
}
int pop(stack *s, int *data)
{
struct node *aux;
if(s->top == NULL)
return FALSE;
aux = s->top;
*data = aux->data;
s->top = aux->next;
free(aux);
return TRUE;
}
int isEmpty(stack s)
{
if(s.top == NULL)
return TRUE;
return FALSE;
}
void showStack(stack s)
{
while(!isEmpty(s))
{
printf("%d\n", s.top->data);
s.top = s.top->next;
}
}