-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack-Array.c
63 lines (55 loc) · 1.82 KB
/
Stack-Array.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
#include <stdio.h>
#include <stdlib.h>
void main() {
int l=0,opr=0,e=0;
printf("enter the limit\n");
scanf("%d", &l);
int stack[100],top=-1;
while(1){
printf("\n------------------------MENU------------------------\n");
printf("1 . Insertion(push)\n");
printf("2 . Deletion(pop\n");
printf("3 . Display(pop)\n");
printf("4 .Exit\n");
printf("Enter the option\n");
scanf("%d", &opr);
switch(opr){
case 1: if(top>=l-1){
printf("Insertion Is not Possible(OVERFLOW)\n");
}
else{
printf("enter the element to be inserted\n");
scanf("%d", &e);
top+=1;
stack[top]=e;
printf("elements are\n");
for(int j=0;j<=top;j++){
printf("%d\t",stack[j]);
}
}
break;
case 2: if(top<=-1){
printf("Deletion Is not Possible(UNDERFLOW)\n");
}
else{
top-=1;
for(int j=0;j<=top;j++){
printf("%d\t",stack[j]);
}
}
break;
case 3: if(top<=-1){
printf("Elements not presented in the stack\n");
}
else{
for(int j=0;j<=top;j++){
printf("%d\t",stack[j]);
}
}
break;
case 4: exit(0);
default: printf("Wrong input\n");
break;
}
}
}