You are on page 1of 14

Waile postfi

HssntNMENT- otAhe Ovous epss Stock


a tt6t3-2) *h) $5+a)
un cti ons o
nd PoP Symbo Stock
O Deline Stock Tmpllment pugh posti
Statk using oviays
which insertion (Pushes)
ovdesed list in
hns A Statk 8 an
end talled the top
0 made a on
and deutton s (Pops) h bottom
ao
whwu
o stack S [ao *, An-1), is On +op ef elmang 6
i ven eomint, cand o
s th top
element On 3
i - Oián 63&
b3&
Push cnPopnor stock
633
ttdeine cize s

n Stsize];
632
632-4
intto P-\
632-u*+
VO1d push t )
632-H+
5
632-u*+5

Size -1)
op = 632-u+5
=

632-u*+S$9
stack ts oves}louo \n");
psin 632-ut+5$+
eturn
print Eden an em
Scan /,d", &stm);
STt+to P ikm;

vo d Pop )

4op*-)
pinte(" statk undnklow")
nLtunn
Dsint4("Deleted im: /d\", s[top--J);
C (A+B*c) * ((D+ E-F) /J))
.a+b)*d+e l tftatd}tc

Symbol Statk postti smbo Stack postti

(+
D ab AB
abt
(+*
abt ABC
*
abt d ABL+

ab+dt
+
ABC *+F
a bt d e

+| abtdte
+5d*C ABC+

ABL +D
abtdte
+C AB+DD
abtdte4 C+
+/t ABL¥+ DE
ab +dee f
+/+ E
hec+DE+
abtceefa
+/(++ abtke f a
B+DETE -

+/C+* abtdtefa
abtdte-fo*+
ABC+ DE +F
OC+DEA F-J
a bt+ dr efa*+/+
abt dfefax+/+c
abtdtefo*+ ItC+| BCDE+f-J
.aot)|a-e* * e A+8 *CC D/E

Stmbol Stack post Smbo Stack


posthx
A

AB

ab

a bc ++C ABC
ab + + BC
abct ABCD
obctd

obettd/ 4(-1 ABCDE

abCt+d /e ArBCDE

abettd/ee ABLDEF

obtt dee + ABeDEF $/-


abCt td/»ef
A
abettd lef

abtttd/ef#9 BCDEfS* G*+


obttdje-4 A*
the is advautages
B*C-D+EFILqt A) Lisin aulat quLR
Une an ueu and how t is
Solved
Statk ive the Algorithn to insest G delese
Symbol postti 'ruelaA qun
an
emen
in

By the
deriniton 9 a9uet, wn we add an elemintin Que
ALk pointU is in vwayed by l, wheuos, when we Am
eVR an
ele ment
ABS front pointes incalajd by Bt in inplt m ntaton of
tis m ay cage pApblLm
asflw s
CDnsldee
o perautions pefoamed on aqutu (uith 817E-5) as oltow
X ABctD
AB$C*D-E
1) Tiiatlepi Quu is thone so, 4x ont =0 and La = -1

ABCD-E
ABCD-Ef
odd elemanks to quuk, thL STOte
e the qulu beomes
) When we 5 ou
+ Ps CD-EF/
ABCD-Ef/ oltows wih front =0 and
+/t
B C*D- Efly
+/ )Now Suppose we delete a elumen fom uu then, th State ef the
f cD- Ef/G4 front= and
u betomes as ollouws, with neoh
B CD-EF/4H

A-8(H D3 E) 1)NoW o ttually we have deleted ejemlnis om quLURas


S0, hin hel be
but ul as potntu is
Syeol Statk
POStti Spate oY anDthe elemandt in h queul,
od ALR Ovef lo Con ditio
pointing at ost potiton
in the
tre, we tant inset nRw elwmenf eguluk
(Keas ==
Si2E-1j S

even i t has an enpy Spaue

this PRoblem hee isanothes variah en e qulu calle


Jo vecome

BC CIRLULAR QueA
-I
OVeo me Dvawbatk ugin
-/ BCDE 4 t 1s The queae wich wRap aDind thi end the akay he

- po $sth0ng art ah ayed in


aAhay
n6DE- +Dn this wnvenion
#he vaia ble foont is chogedfront vatta be

wnte elockwise fom location tth e tont


poindts one posttson
tlemant in the quLue The unchangt
funtion ev aluade
enpsassi on ond
con vet the ouOuing epoe ssion posttx epsess on ond
fo% the ven data
unt'on ewaluotu POst ezpusgi en
1ntade< stdio«h>
oudR <onio.h>
Delte
Add incwd < madth>
intluds <stsirgh>
o i d dequuu t) ouble ompu (ha symbol, double opl,
4tdekine mAx doulble op2)

(30 t= =1&%
sead = =-1) susith (snmlool)
nt Asont--; 0 u is undnttow"':
pi
alge Coon=se) Case '+ setan opl t0p
enqueu Cin m ) The deluHd aanarN Cose : Tetuhn opop2:
vOd poin case : 3efn opl*op
s8% , Rsort3);
=*-1) Case I 1ehuhn opi lop2
fso rt ==-i && ean
s0nt=-1, cose
case : Kehun po(opi0p
sont-0
daut setun o
vean)itEm;
else

else i+tsea» ++) }. MAx = ={0rt h e daluted almet 1shd,


uL is ovetou)) pai void mo1nl)
print
elee MAx dauble s20),ses , opl,0p2
0 t Aont +1) o|l.
nea veah t+) '1: MAx itopi
cha pos{ia(P0Jsumbot
LneaS - iHem,
er sep)
pint"\n inta +he postix expnesgion #\n"),

to p
or li-0 i< stran Cpostti)) itH)
60
o

symbol past}a 1J;

stt Symbo- "o'


b) Additn c) Delton else
63 a t | h b-* 1* Postti

op= s[op-3 symbo Stade


oP1 s[top-3
e tOmputs ( smbol, eplyop1) 3
3
62
62-2
64
1Stpp--3
sesusts is |#\n, Tes),
Phut nJhe
aetch C),
-2
-2
2
a) a b, bz3, C=\, d:2,e eu
C(a/b-c+d))* le-a) rt)
Symbo Stack Postia -6, 6=3, C=2, D=s, E=\,f-
Aee-D*+ Ef
632-5¥+ \
tock
Posta

D
Cct
ab
C
abc

abl

t/t+ ab-d
Sybo Staes
abt-d+
6
abl-dt
3
abt-dt/
632
ob-dt)
61
abt-dtle
6IS
obt-dt/e
abt-d+lee
obt-d4+ lea- A
abt dt|ea*
abt- d+ |ta-* C
albt-d+ lea-C*
(631-2+l46-* 14)
untion ox Touwen lanoí sote
th funthon o% 3 disks uoth
sto tk taI nee
digon
Void towesit n, cho%
b
ATsJ,har B[5, chor c[

tuun

TO (n-1, A»c, B)
Print S*S\+", A, c)
38
TOw(n-l B, t> C),
6 5\-u*2 3 +4
ogosm ovhe epresOn
ate
Smbol
Stack
void moint)

psitt"Este the 0.o discs to be tanses ved \n")

Stn<)
6 162
616 2 3 eit lo),

else
62 R
pint+ The toilouwing mo veg a 0quiyedo

TOwe [n, °A,°6,*c"),

fo n-3
The foll ow4 mOVR anL equised o n =3
Wsite u n tion dou he s wlan
ULR copau
dy nomicaly usin aUtiays
Noid inse yt aC)
3Dsts
Count =s12E)

L L poi atteful incsease


&sI2 S12EA2;
se by \");

LI * ) LalloC Si26 e tnt 1)

i Cron veaa)
6
o i SIZE -2 izfsont, i --)
A A

sonH

Tean =lar+) s12E


Creas im
Lountt,
cope atong hat CAn vod push C
) Dekine a Sstack tapladn the ditfeunt
ond Shouw hen
peno md stotk usinq *he u n eiOns Lng
Tepresetodtien.
iltop == Si2e -1)
di qt onate

Stack s On osdoud which nstioS lpushe point ("statk ovesylow Io")


MadR at n end catled tha top stun,
ond delti ens lpops) a
te oan ttm:")
Stack opRNaAONN
Pr
sLan d , &tem)
Stack Cyepte stttto P e m
dewnt sidh is used to nst o8 duleeis spe ked as
The
SPOPC
strudtune tha onsists r K seld eLment s om the stack isLaled pop opehatton Th
Delti on

(maa Stack Si ze) :=


imnt s dalated somHhe ope+he stock and sny ona
Stack Cseakes
100 / maaimum Statk STee*/
#dotne MAx_STA Ck-sizE elment s dolted at
p e de Stauct
void Pop)
Lto p==-)
3 elumtmu
emnt stack [MAx-STRCK-S12E]
pstad statk wndnHoul",
stun
iat top =
-
Delated H m: "hd\0, s[top--J;
a Boolean 1s Enpty (Stoce): top <0; pri tt
3. 8ootean 1s Full (Staek) : top > =mAx-STACK-SIZE-
ToP -o
ToP TOP=2 TOP
The IsEmpty and Ts ful epehations ahe
iple, and is tmp lemuntd ToP-- stak[oJ- Stak[ij2 StakaJ-3

direety in th pA0q Bam Push and pop tunchion s. 6ath o these


f u n chons dkume hat+he vaiables Stack and top an globa

Push ()
Fun tti en push chitcks huthes statk is tull y it is, it cals statk full L)

whh pAlns an eA msag and teaminales elcALkon.


PUsh Push Push PoP
hen the stack is not u , inumint top and asign Hm t0 Statk Hepj Empy
Stack

9omtic Rapsestntation Ahras


penodiony
0-Ven nauN a numbas
pToas
hA-dd
and <std io h>
Dikkeardiak betwean se unsion #indude
h>
nctude KStdlib»
Aat0
total Even ()
Propes Rewsion
Aet &instruckons
n
i man C)
Funthon Call itseuk
baintion sepe adedu aauted
psint(l.d \n", to tad Even (2 ) 5
Foy un thons for LoOPs
APpltahon
when 4he tminadio n
0nditson int totalEven (int n):
paga ca3e, Wheve
Temdnadn Thsough iRTator teags to
tos hR
these uttl b& no untkon a
be Satistd i ve0=1)
ven=100)
sed whn ode size needs e
whun Aime tomplexits
neads to b Dal oned aangt
to be smal, & ime
uodl si
euponded
ompl\ S n o t an SSuR
an

Smaultn c0d si
totad Even (even 2),

T ve h lgennaulyH Rula ive Lown H omplu rrtwn ven,


ompu p o n t i ) im ompea gonNely poly nomad og9

8 Dekine q u . ist
*h di65*3ENT Ps 4aus 3tote the

4unckon O% din co plain houo you OveALom limitodhong


th
w tato0 A
wbes
a) Addan - odd nabuial
specby the Teqised -stokmeS and digsa motic sepseserdtahon
n c u d s <stdto:h>
Hintads < stdib.h>
s n ordnud st in with inseutions
nd total O dd cy
dutions (yemoNals and pops) toki
and
int man t)
addithons, pushes)
pri dg.d\o", totaloidtu); eneds"
at dkOLnt
plate
added Clled
i t tota0dd (intn) Theend
whith old elLnts anul deletd
the ve ad hadt om

Lodd>0o
Called ront

ineas q L
oY Simpu qR
else
40ta Odd (odd+2) Double ende Qu
ti)
A odd i) Prioria u u
mitaion Orn0 8uu and nouw 4O olean Isull (Sta ck ma x Stack sige)
Q-NO 3
(no elements in
statk= moa sta tk sige)
13 Wite note on Hekman's untion setuhn TRUE
else
n omputabi thAosy, th AckanmannuaettOn, nomed o vetnn fALSE
wilum Atk emo nn, is one t h e gimplust and auest-disovened
s
eRompks oatotad tompuctable
funttion that not primitw
Statk Push (stak,ittm)
tunetion As total and omputable.
u sive A pimitve e wn sive i s Fuu (sta ak))
n illusttates hod nof a toftal ompucable
a Atkes mann Stads Fu
PimiHve unsive. Atts Acknann's publication ehis n els
authrs inset m into fop e Stack
(whtch had thste n0n negative inteje angume nts), many
it to suit yauous puaposes, So that bodny th Ackama nn
molitid
funten may {es to a numub ants thi ongual hantdn Boolean Tstmpty Lsta x)
two-angument
tekuMann Pete funhon, I(Stack == cAtaks (max Stack size)
Oe tommen vegien, the
nonnegahre integas mnd n: ALkun TRUE
def ined as follws fo
elge
ALfun FALSE
nt
m-
Almn) ln-13)
LA n-1, A(m,n-) my0 & n>o Elemet PoP (Sta.ck) :=

(1s Cnply CHac))


Degtne Statk and wte tKL ADT
bStack Dmplment push ond pop
Aetuen
else
funchons fos Stack ufing Kays h Statk Hal G Stae emove and ALfun to ellmen the
Enpty ond/hon
DT eStae top ethe Stack
*Objects : A aite Oxdoud ist wthe0 0 morR eliml ts forter
tfunctorng
Fo a Stock e Statk, item elen ent,
maXStacks2e e posifve iNg es
# S tack ceates Cmax Sta ck si2e)
CYeate an emp Stak
ChooSemax Size max Statk Sip
O Toesent epe
Apo9S)DIe Mp umlntaton:
houd 0udd you modol C maze, wh
Desest be Pse doAON h possiblk tiong to mov in
Poths ond 1pvesents o obGuerS What
moves aNe penmit Aed in
the OSV)a, move, nf
with S alloudable obtoirad som
n enompla maR togeth
mod Psovidl
mods
pe da Stzut
movas
moves and toblR
Shost irrot;
heot int hoviz;
T h L most obvious hoice is o - D a0IA

>0 s th open paths and bone

Notice tha not eveny posiion has ght nuighboLDs ektseds move Ls J * arsa movas
tan sor souad e oT each diseution
S o awofd thucking orh bosden tonditons w
* we ae a posion, mage sou [oI3, and we wish to nd pon
bosdes 45 shus aa mxp maRe i Tequ**
MAe b
te n t move, mage[sou1{w), we set:
m+2) P+2) ddia

The entsanu posion LJ[ a th et Lj next-souo= TOu tmoue[d8).vot;


netol ol * move [ i ) .hosi2;

Tob ek move
Name mov&[divext move[dis]-hosig
oo o O0 o N

NE
oo o o o
St
SS

NW

i-T0-3 N

E Ii+
yofd duuLuR t)
fatorial wwmlb
ecunsive pronomn o

inthude <Ståao.h>
incdude < onio»h prid+duaue s
empty
Noid moinC)

nt n,f printb Deluted tm: /.\n", Tsont +43);


psinAEntex o posttive ttg83 \ ) ;
sCant (l.d n) pioity queu and Deguue
ali a short noe o
att (n) suck
Yiosi Sugs p o s qu 1sa ollR LHon ok elamo nks
psitt fattosiad edis d,n,); psoiy oand Suth that the
allmanthasbeen assianed
that ench and po0LSses omessm
he
elemants 09 dalated
itat lint o) osde in whith

follouoing sules
.mint
vetun n u)S
alamnt eigh prositis p3oussed betose any

n-1 olowesh prioriy


tact (z); Tuoo etmnts with th Som psiori ty e pod S s ed alloidrg
xetusn(0 *y), wa addsd to t qutw.
ovdun in whidh hey

Rupsesentadion ot osiG dusua


ist
Detn Q s . mpomnt QIneert ond Qbeloe openatsons n ajv Oneua

insestt) ene- A

Eauh node in the st il Lotaln tnee items e intosmedion s


link numbr LINK
void enquu C) Nr0, apri0s
mb PRN A
Cadem an ntovmoton eld

Node in thi i
NS4m, Nodt x psecedes a

e a == S1zE -1) has bighes priovi


than y
owhin x

Aull)s haue the Same prio but


ouLu is b) when boh
Poi to the st befove y
& dded

the tm\n");
Ps Ext
Stanl),d", &1tm)
DEouEvES
st in whith
A dquu oue ended qukua s
med a ithen end but not th
ellmens Can be added 0

middle

Kepye sentstion

Deque TSmaniained by idlaA annay DEQUE wth pofes LEPT E


RIGHT whith point
Point Ao th two erds edtau
with H elmund maintoinad in
t Shous dia
ocottong
wth N=8 mmo

be ugad t i nindi
d icot
cae that digyu
aa digs
onditon LEFT NULL w
e
s p DEQUE
heB6sccc bPD J
. 8
2

Two yaian ot DERUE


Input-ALstaitted dtgue
dutput-ALstaictd dgue

You might also like