-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStack Array.C
More file actions
66 lines (66 loc) · 1.17 KB
/
Stack Array.C
File metadata and controls
66 lines (66 loc) · 1.17 KB
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
#include<stdio.h>
#include<conio.h>
void push(int st[],int item, int *top){
if(*top>20)
printf("Overflow");
else{
*top+=1;
st[*top]=item;
}
}
int pop(int st[],int *top){
if(*top>=0){
int data=st[*top];
*top=*top-1;
return data;
}
else
return -1;
}
void disp(int st[],int top){
int i;
printf("stack is\n __");
for(i=top;i>=0;i--)
printf("\n|%d|",st[i]);
printf("\n __");
}
void main()
{
int st[20],i,cho,top=-1,d,item;
do{
clrscr();
printf("\n\t\t-----Stack Menu___ ");
printf("\n\t\t\t1.Addition");
printf("\n\t\t\t2.Deletion");
printf("\n\t\t\t3.Display");
printf("\n\t\t\t4.Exit");
printf("\n\t\t\tEnter your choice: ");
scanf("%d",&cho);
switch(cho){
case 1: clrscr();
printf("Enter the item to add: ");
scanf("%d",&item);
push(st,item,&top);
disp(st,top);
getch();
break;
case 2: clrscr();
d=pop(st,&top);
if(d!=-1)
printf("popped element is %d",d);
else
printf("\n underflow");
printf("\n");
disp(st,top);
getch();
break;
case 3:
clrscr();
disp(st,top);
getch();
break;
case 4:exit(0);
break;
}
}while(cho!=4);
}