forked from MiguelDordio/Data-Structures-Implementations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
38 lines (31 loc) · 671 Bytes
/
Copy pathstack.c
File metadata and controls
38 lines (31 loc) · 671 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
#include "stack.h"
stack *create(int size){
stack *s;
s = malloc(sizeof(stack));
s->size = size;
s->top = -1;
s->stack_arr = malloc(sizeof(int)*size);
return s;
}
bool empty(stack *s){
return s->top == -1;
}
void push(stack *s, int data){
if(s->size != s->top+1){
s->top = s->top+1;
s->stack_arr[s->top] = data;
}else
printf("overflow\n");
}
int pop(stack *s){
if(empty(s))
printf("underflow\n");
else{
int del = s->stack_arr[s->top];
s->top = s->top-1;
return del;
}
}
int top(stack *s){
return s->stack_arr[s->top];
}