0% found this document useful (0 votes)
5 views11 pages

Stack

The document discusses the implementation and operations of a stack data structure, including push and pop functions, and their applications in various scenarios. It highlights the importance of checking for underflow and overflow conditions, as well as the use of stacks in parsing expressions and balancing symbols. Additionally, it touches on dynamic arrays and linked lists as alternatives for stack implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Stack

The document discusses the implementation and operations of a stack data structure, including push and pop functions, and their applications in various scenarios. It highlights the importance of checking for underflow and overflow conditions, as well as the use of stacks in parsing expressions and balancing symbols. Additionally, it touches on dynamic arrays and linked lists as alternatives for stack implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack:) ered colleehon it

hat te iehiug
of elements in guch a wy
place at one
at
cnd delehoy take
hat s nsered at te daut r
The element
he one delekd Bt hert tore, called a
Last Arst ont [LIFo] (o9 [FILUg
’ erahony push () hserhng an element
Pop() an elenent.

Rushl3)
30
-Pop(30) 20 ’Top.
20
20

anelement
’ underflai- Trythg to alelek o pqp
frorn an empty tek.
’ averflas!- Tying to thsertconpsh an element
fron
e.3 applicahins Inhy -t -þosttiy Gersion
Eralah.
Reatsia (tanchon Cals),
web bras cvs (pagenited histoy te
-) erahing dn &lack noT) push), pp().
oer posaile ogeohmy ) findsize () ’#folement

Sfnd top(0 -> Last hse ted olerent


Is emphy C) ’ checkempt (org
en not
Istulll ) ’ checks hether stacde full
(on not.
Tmplemenaion sf stack )
N=6

( wing an ausy ) 2 3 4S
push () be
void push(s,N, Top, ) , eerent to b Anseted

Top ostack

A4 Top +l== N)

eftnstack is arerflew");
esit();

X
Top tt
[
s ttar;

TC Ou) AQcey
Pop() - 3

int

exit);
else

T.e ) o) (al sey

&e otstack ts Gxed.


Ahragh Ahe excephon.

) Dyname Avray pdeenahin tan be wyed


to Bol 's pvoblem.

) Doudiag e dize o an
Cuwent et an
famothied) is o)
Therelost, ile tie Conplexihy ten Djna rmc
pexfomy puah ecahion

heahes to mar it a
and data 't Copie
d hat
dable jze i's generattd

takes o(o) hme.


Second elerent push
3 l, Hen far
n:2

n=4 d onb le agun

datble agan

| t2 +httl6 31 (2n
Aogn h'mey dacbbe
he

talces place

n(2) 2n = 0
()
) thy Cant we make it in toll arg hway:
2

n) 1+244t-tn
)o -n,Notelkuent
() Uing linked i'st =)

problen of stahc ahhay and dolng wey.


Soiesi e hthe Caye of
dynam'e asy
push():

Vid push ( Top, )


node)).
mallocl Bisel(ehuct
P=(stuct node 4)
nonee to
to check.
nest = Top
Top P j

f( O)for al
gtacks tmpt, aperah

Hasenerj delehh

Complele stack
ese
J'-p aha;
Top = Top ’next;
freel)) Nul, Yetan(s);S
Hpicating :)
4 ymbol, (bracket) :)
&tak
8tak Can be wed
Can
Salanced Aynbol (o99 not,
e9. [(a+«)* (C +D)].

empty then geneyate eror


( I l occus puh hto stack.
i) f opening bradeet
ccuy an &tack s
(iöi) f cAosing bracket )
chek h e
not emphy then pop () and
Cospondi) cloing oracket it &ame meas
()
hen ma huthex unh expreion not Completed

Hat are not


[(kt) k(246)). balanced
check emphy Caye
P o p c ) ) mated

the exresion is balanced e o4blanced


(ena)?
0matehed

()madehe!

(R) Taf to pas+hx (onrertjon =)


Tahx epresentah'on (standand aitmehie expeuin)
(A+0)* c ’ AtB*C.

pot fix nepres entahog oPerarnds then opevaBor


accoding e precedene.
A BC* + (pati)
freky eprsentaon peraf Hen operands.

acording t"prec edence.

bosthx
(

4t bxct(dxet)q

qbe* 4dexftgxt

we wie sperator ak
Hrangh 8tak

k
tput

e preedence as Copahe
Stale y t , So check

*>t ’ pyhl)

G t , So here t< X ’ pop() and putinto

One pasy to
until not reachhgte Case
nput expreliog nen t> prtcedence of soyertor
when

stack.
L(ghest precedence in Hi's
emax-S ieet expreson
pevaty
6act

Gt ’ ( nd net he pop ped unt{)


(omey.
Herelore push *)
t’ +< top * ’ popl)

Ls* puh )
at lost pC) al element fra tht
()
Auoiakm asociahity
l-R
I ()
22 L-R

3 (4) R-L
e sponent

e ble -4 *cfd t f ng
Gpsthx -) be /acr* - t t

ole be/a cd1 *-fgnt


perator
’i2eo
Atadc.’52e oerator &tack )3)

e y c e r u s e

(atet-ola) ‘(e*(f13)/4)
J3

poshx c*psiay evalaatim-)


8tack to eraduak aa psthix
We hee d perond epresion

G523 +8 t3t *

pushed hto ghack


operands tll be
operatox occw
-’ ohen operan d -2

sperand-1.

rator)pe-2
Opevand stack perahon spe1 (ope
(0i)
(iv) puh (rsLt).
pryhl)
t ’ Qt3 )(s)

’ t ’st4o 4)phl)
’ )(

’6X4 - ) ( 2

Aine of operand Atck example


8)

Ah He ertnbtin
of ntor tack a d op e*andataek

perator tnckseguire d
qatlix
y opeva nd stack heguired
eranaed Ans

ole- 234 L4n1*t2-L/t

4 unit t rator tac.


tpevator stack

4! 4 S unit gerand tacle


3 4=)|2
2t (2 =)y
14-2 =) |2
Gperendht
t t =) 19

You might also like