Stack Program
Stack Program
ncl
ude<st
dio.
h>
i
ntst
ack[
100]
,choi
ce,
n,t
op,
x,
i;
voi
dpush(
voi
d);
voi
dpop(
voi
d);
voi
ddi
spl
ay(
voi
d);
i
ntmai
n()
t
op=-
1;
pr
int
f("
\nEnt
ert
hesi
zeofSTACK[
MAX=1
00]
:"
);
scanf
("
%d"
,&n)
;
pr
int
f("
\n\
tSTACKOPERATI
ONSUSI
NGARRAY"
);
pr
int
f("
\n\
t--
---
---
---
---
---
---
---
---
---
---
");
pr
int
f("
\n\
t1.
PUSH\
n\t2.
POP\
n\t3.
DISPLAY\
n\t4.
EXI
T")
;
do
pr
int
f("
\nEnt
ert
heChoi
ce:
")
;
scanf
("
%d"
,&choi
ce)
;
swi
tch(
choi
ce)
case1
:
push(
);
br
eak;
case2:
{
pop(
);
br
eak;
case3:
di
spl
ay(
);
br
eak;
case4:
pr
int
f("
\n\
tEXI
TPOI
NT"
);
br
eak;
def
aul
t:
pr
int
f("
\n\
tPl
easeEnt
eraVal
i
dChoi
ce(
1/2/
3/4)
")
;
whi
l
e(choi
ce!
=4)
;
r
etur
n0;
voi
dpush(
)
{
i
f(
top>=n-
1)
pr
int
f("
\n\
tSTACKi
soverf
low"
);
el
se
pr
int
f("Ent
eraval
uet
obepushed:
")
;
scanf
("
%d"
,&x)
;
t
op++;
st
ack[
top]
=x;
voi
dpop(
)
i
f(
top<=-
1)
pr
int
f("
\n\
tSt
acki
sunderf
low"
);
el
se
pr
int
f("
\n\
tThepoppedel
ement
sis%d"
,st
ack[
top]
);
t
op-
-;
}
}
voi
ddi
spl
ay(
)
i
f(
top>=0)
pr
int
f("
\nTheel
ement
sinSTACK\
n")
;
f
or(
i=t
op;i
>=0;
i--
)
pr
int
f("
\n%d"
,st
ack[
i]
);
pr
int
f("
\nPr
essNextChoi
ce"
);
el
se
pr
int
f("
\nTheSTACKi
sempt
y")
;