-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_using_array.c
More file actions
49 lines (49 loc) · 790 Bytes
/
stack_using_array.c
File metadata and controls
49 lines (49 loc) · 790 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
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#define size 5
int main()
{
char st[size];
int tos;
tos=-1;
int i,ch,num;
do{
printf("\nwelcome to impolementation of stack using array:\n");
printf("\n\t1.push\n\t2.pop\n\t3.display\n\t4.exit\nchoice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(tos==(size-1))
{
printf("\nstack overflow");
}
else
{
printf("\nenter the element to be inserted\n");
scanf("%d",&num);
tos++;
st[tos]=num;
}
break;
case 2:
if(tos==-1)
{
printf("\nstack underflow\n");
}
else
{
num=st[tos];
tos--;
printf("\nelement deleted is %d",num);
}
break;
case 3:
for(i=0;i<=tos;i++)
{
printf("\n%d",st[i]);
}
break;
}
}while(ch<4);
return 0;
}