4 Thque

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Wsite a pTOqsam o 1llustrat push) , Popl)

8 Exomioe ond stack.


Operation of
a
sEmpty),isFullO

PoqTam
# includeestaio-h>
itt max&ine = 8

int StockIRI
nt Hop--1
it tsempty C
Htop= 1)
Teton 4
e lSe
Tetum O

int fs-ful t)
(top = =
max.Size)

Tetoon 4
elle
etosn O

fnt peek ()
leton stack [top];

fvt popc)
fnct docta,
H(11s emptyC)
dala- 8tack Itop
Hop toP1
etoin data
else
Privf stack is emptt)

inet push (tvct data)


14C totall c)

op-topt
Stack top] dot a
3
else
PrinttC tack ts ull. In")

Int Tmain ()

Push(3)
Push (5)
Push ()
Push o)
Push1a)
Push( is)
Push (14),
at top ot the _etack %d n Pee k C))
Privett C"E le mevtt
Printt s lementt are In)

While C!ts emphy))


fvct data= popt) 3
Prlvelt (d , dorta)
Pit4stack-tull: .d \ , 1-tull ()? 1:0o),
Privet4 Cetackemply:7.d \n" fsempty)2 1:0);
Poivctt (.d", Popt))
Telon O'

Ouctput
k lement at top of he stack : 19
lemevts

3
&tack-full: 0
Stack emptyt 4
etack dopA ts em pt

Fxplanaton! The
n ptoqram heTmaximom Size is 8 Ci.e ) oto .

4hf t
he add ol eoments. PopC) oderatton
PUsh) operatton to
he
oloes he elimimatton tetomutt.butt An thic program
&tack f full nen he etumact get elimino.td.
isempty operatto chec kethe tack f-fmpty.
iSfall opeyation check-ne etack tc -full.

You might also like