0% found this document useful (0 votes)
13 views

Stack Program

This code defines functions to implement a stack using an array: 1) It declares an integer array stack of size MAX=100 to represent the stack. 2) Functions are defined to push(), pop(), and display() elements in the stack. 3) The main() function gets input for stack size, displays menu, and calls corresponding functions based on user choice, exiting when choice is 4.

Uploaded by

satish kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Stack Program

This code defines functions to implement a stack using an array: 1) It declares an integer array stack of size MAX=100 to represent the stack. 2) Functions are defined to push(), pop(), and display() elements in the stack. 3) The main() function gets input for stack size, displays menu, and calls corresponding functions based on user choice, exiting when choice is 4.

Uploaded by

satish kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#i

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")
;

You might also like