-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_using_struc.c
More file actions
53 lines (53 loc) · 811 Bytes
/
stack_using_struc.c
File metadata and controls
53 lines (53 loc) · 811 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
50
51
52
53
#include<stdio.h>
#define size 5
struct stack
{
int st[size];
int tos;
};
int main()
{
struct stack s;
s.tos=-1;
int ch,num;
do{
printf("\n\twelcome to implementation of stack using structure\n");
printf("\n\t1.push\n\t2.pop\n\t3.display\n\t4.exit");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(s.tos==(size-1))
{
printf("\n\tstack overflow\n");
}
else
{
printf("\nenter the value to be entered\n");
scanf("%d",&num);
s.tos++;
s.st[s.tos]=num;
}
break;
case 2:
if(s.tos==-1)
{
printf("\n\tstack underflow\n");
}
else
{
num=s.st[s.tos];
s.tos--;
printf("\n\telement deleted is %d",num);
}
break;
case 3:
for(int i=0;i<=s.tos;i++)
{
printf("\n\t%d",s.st[i]);
}
break;
}
}while(ch<4);
return 0;
}