forked from AdarshAddee/Hacktoberfest2022_for_Beginers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_arr.c
45 lines (43 loc) 路 929 Bytes
/
stack_arr.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
#include<stdio.h>
#define MAX 1000
int main(){
int stack[MAX];
int size,ele,ch,top = -1;
printf("Enter size of stack : ");
scanf("%d",&size);
while(1){
printf("\n\n0. Exit\n1. Push\n2. Pop\n3. Display\nEnter choice : ");
scanf("%d",&ch);
if(!ch) break;
switch(ch){
case 1:
printf("Enter element : ");
scanf("%d",&ele);
if(top < size-1){
top++;
stack[top] = ele;
}
else printf("\nStack Overflow!\n");
break;
case 2:
if(top >-1){
printf("Popped element : %d",stack[top]);
top--;
}
else printf("\nStack Underflow!\n");
break;
case 3:
if(top>-1){
for(ch = top; ch>-1;ch--){
if(ch==top) printf("%d <--top\n",stack[ch]);
else printf("%d\n",stack[ch]);
}
}
else printf("Empty stack!!!");
break;
default:
printf("\nWrong Choice!!!\n");
}
}
return 0;
}