-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackbyarr.c
77 lines (57 loc) · 1019 Bytes
/
stackbyarr.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>
struct stack{
int size;
int top;
int *arr;
};
int isEmpty(struct stack *ptr){
if(ptr->top==-1){
return 1;
}
else{
return 0;
}
}
int isFull(struct stack *ptr){
if(ptr->top==ptr->size-1){
return 1;
}
else{
return 0;
}
}
void push(struct stack *sp,int val){
if(isFull(sp)){
printf("\n Stack Overflow");
}
else{
sp->top++;
sp->arr[sp->top]=val;
}
}
void pop(struct stack *sp){
if(isEmpty(sp)){
printf("\n Stack Underflow.");
}
else{
int val=sp->arr[sp->top];
sp->top=sp->top-1;
printf("Popped value:%d ",val);
}
}
void display(struct stack *s){
while(s->top!=-1){
printf("\n Elements of stack are: %d",s->arr[s->top--]);
}
}
void main(){
struct stack *st;
st->size=10;
st->top=-1;
push(st,4);
push(st,6);
push(st,1);
push(st,3);
pop(st);
display(st);
}