0 ratings0% found this document useful (0 votes) 48 views18 pagesDSA Assignment
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
: Pare ie ca,f)
» Pah D" gals stack pond add C" to the
Rit Sean a Sree vat gnt to emu ara tA ay eee ane aa
sits 3 bob for ean element of @ Until dhe aieck
Moraes
frmt of @-
& is embly ‘
BTL a Wghk parenthars 9" se emeauntoned push Tt odo |
. STACK: : 4
Us sh om obttord > erceumbured ,addi b/ te Paw
FY AL om oheratr@ I encourtoud ; then >
(A) Repeodedly pol er STACK Grd add te P each chorolor
Con Asp of the Stack) Which Ver the home prccedere OF | wy)
om Wigher thom @ Lith tee bh of the wads ipnet equal 65’)
Ch) Add @ to STACK .
E TE a Left pruathos *C io ew Combard then
Co) Refeatedly pop Sem STACK ad add to F each shorter
Com the toh of the SUCK) Util a sught porextherbs 3" ia,
Re con tud -
i) Remove the sight borew
Revene BP
exif
Tre oboe alyorithn Convats the infix. exprernion Inte
Ref
Yaexits [Do vot add nat renee
z
2ee eae
Agorithe > Evetiate CPSC)
THe ollgatitnm finds the VALVE of am arth metic Cxprorh
OWN In Prefix notation «
A Add 0 Left parntheis “C" ot the wbnting of P.
% Ston P from right le Left ond repeat rtep> 3 GdY
for each element of P until the £efd) porethais “Cc
jr Sncouniaed: t
B I an ohoced in encountered, pub
af an opuain @ in Cn Coumbercd , Unter : R
Cor) Rewgue tre wo teh elements of SUCK, bree A in
octet cleat | ond int mest dor hg eleremnt «
(bh) @yaluate A@Q:
Cen) Place re rould of (b-) hack om STACK -
Get VALUE = toh elemat en STACK-
exit
\4 em STACK
\
NE Ww
The above allgerithn evaleates the Prefix enbremion Calnich fe eee
prevignly Converted from ‘\ofs
Towention at the endo} Lowhed int
S é.
eh tem in te be inmrted ob &
one Wl Apaverse Bre Lit, Wamng a peinto Vo able
© \ravering Continue ade Reng op Linx [PTe) Nowlin
WOEBR ren (TR we at nd node of o Higlocalrier Ae |
GE Ubdobe PTR fg We agemert | PTR LINKLPTAI |
Alla completing bavoak ) tein ob ond node ,bothen Get |
|
the end of a Lrkel list
PTR:
net Link Ceres New bh Lane (Neo) = NOW
Repeccieae Wel UNL oma CTR pointe) Soames Node.
3.georthon >
INGEN® C INFO, LINK, Slant, Mvoil, Bite)
tP Avoih= Nort ;the white Novation |! exit }
eet Neo = Avoid , Avoil = Lank CA QI }
Sek INFO [Keel = item 4
SP LGtoats NULL her
set LINK (Neol= Lew
Set PIR = Stort
Retak eee avite Lana cere Ff NUE |
co a Ne CPTRI ‘a
Sf Lane (ered = NOW ten
goed Lank [PTRI= New & Lane tweod = Wee
Ghert Ged Start = Neo:Ddetin a
@ Ditetin_ok_te ond of Sed lint teat 7
ee ie
alert Lhe Qovt ~node of Divteed- Dist i>
Mare Gotta ne glist Jue\s) gaibeienpuom onic)
ce Jrovesing continute css Long o” LAN RPTRY HAOLLA IY
words PTR io ot end node of a Sinty While e
Anayening Aeep Ine Location of preceding node AY beinter
Nedolle SANE
Wien dnaverel stepo, °TR \poldss tre end node j and
SAVE \oldn he second arb node of a Lintaed Sont-
To delele end wodt f @ Lvhed Bist, oe 40,
LankCsaved = NOL yard & Avail: PTR. |
|
Adgerithm? DEL ENdC 1597, LINK, ENC sotont, Avail)
Sndetbor
TE Stor = Nv y then pant S excep | ext
do be deleted:
ne LawkCeTRA= A
L
2 af Link (Stext] = Nur thew
pet Stes Lani fotextd = Avail & Nvaike stort
ond Start = put ext:
% Set SAVE: Storr & PTR= yank Leteodd
y Revert qtely S carite Link Let? ¢ Nout
s cet SANE = (TR h PTR =LINKCPTRI
&
af Von cet
wet yank L
RY = NOLL hen
SAVE: NOLL KLsNK CPTRI= Avoil { Jvei we PRae:
HE Txavening a Doubly tnked List ©
‘page Be >S
Cuptsse eleva loglsavanes Ucar OAC a piaceeeanars
rode exaclly ence
MG ate ere Coal pein heen te Gh U anton
orate, arayy , FORW ond BACK Gud tee ponte varafle
FIRST amd LAST ~ An Wnformodion Field sxFo elvich emteing
Vhe date ef each vedeo:
A Pointer fied forw obich Comtarme Lhe location of the
rnent node in Ihe Lat
D pointer field Back ahich cenlois
preceding node rw the List:
| Pee vosate Foret owes, Tees the fea
| Amine Lost Gad LAST pesrich pore tho the Last node Im
| FIRST
Last
ao Gt aacoa
Pc Vicvune 7 daly, Bnted Tat im Jouwed
Brcclisn a well o> hockverd Unb
Phe Recation of the
C) Thawte al in fran Satie ?
Agorthyn 7
Were we Use pemtor \eriahle PTR which “bows aR
anode Yrat Vo cwoently beng proceed
FoRW LP IRS pein aa snext. made ve be procerseds
So, tre sralemend F1R = FoRW LeTRY Ages PTR be the
ont Jo next node Ned Qatlogr fortsand direction)
TRAVERSE (DUST, INFO FORW, FIRST PTA)
4. Geb PTR= FIRST
RsGY TNee)
‘iceclion > Poge No >6 ¥
Here oot use peintur vovoble PTR @hich feinte tothe
node thal ‘ve curently bang proewred 4
nck LOTR] porto fe the Preview ae ONC ERATE
sailor PTR notde the Post rode of Lint
So, the platement OTR BACKCeTRI move PTR in
Aockweard durechen:
Moot > Travore Bock (D127, IN Fo, BACK,
4, SA CTR= LAST '
Releor pies SAU orite ere $NUL
%
B Aypdy proces 1 sneotet®)
us
5
LAST, PTR)
anak = eAckte Te):
S €xil-
Yt Trsertion i _dowbly Loted_Lint >
aaemeverticn to add. ew ede ine ceteet
Rust Thee con Ae Aifferrt core é
4 Senertien at Bre Aegieniny of Une Lost
% Teodio ab vhe end of the List =
y tesention afte the mede with & given Recation:
Tnsention eee Poul Linked List:
ol here Coren pomelimets a nts te data ip be
i es \wwerted hui hoe is ve avaiheble pact, 1%, the
Bec Bik we embly: Thin scthuetlon? vst Darnintore
\ Nas Praile*\o' ¢ Amik =Norte**
e Ke Ainked List 0 memory: AW oa SL \rertren olgoriim ill woes 2 Folloving stebe!-
Sch-t> poets apace We available in doutly Breked Lunt
IS ot j.e- Avail = Nort ,
Then VE will punt the wermsge “over flew”
Shep? > Removing tne Jui node from the Avarl Quot:
Using the vawable Neo to peep frack of the Location
eh the new node thin eteh con AL en plemented
Ay the bale ok ansignmen Ys
pew = Avail A AvoiQ = LAN KE Ave 2T
| Step->> Copying new whom ation ‘cle Ane nev node: In
othe werdss, ANFOLNeed =item
Need fo, Bie doubly fnhy Jict ne to cack tyke
of wrrbdion Gt have te whdate Aoth FORW ond
BACK pomre. orray accarding jp wsetion perition.
@zsetea ol the Aegmering of a doubly Lnted Dist >
Subhor Our doubly Linked Lint io not workd 2 we
pam fo Wot a nto mode at the 1°> berition.
20> :
yNe@FaRst CaNro, FORW jBACK, Sw Fost BLort rt)
4 ap Avail = Nort teem pant © Overfiles & exit -
Reet Nto= Avail aes |
x Be hvac tam tank, (Avo © ob Nolh= Fors Dyait Fie eas
ae f Sete
Ged INFO [New = tem asthe 1
FoRW [Nev] © GFinst
: NULL ,
eee BACK Fianl]> ABN ews
she N Cte mete aeBeaten by Abe end oh doutby Dndud finh > CORN ED
dw , Hew Ul wr a clowthy Rink eh Jint 2e we
Nove co bomtor variable Last @hich pointe be the
ont node a hed 2%
meet soe tater eo je Lred for satodng ie crailable
INLASTLINGO, ForW, BAK, first Last , eon}, Nok)
42 TY Avoih= NOLL then LAte ~owefles” & erik
gS Set New = Avorl
QR Avoids Lank CAvid
Br Seb INFO [Nee T= there
Y cet ForW [Lortl = New
FoRw (Newt: Note A Qack tee L-Last
& Last = New jaalleg itt Me Maru
S Gat Ree at Ve
Ix] Uy
]
Fe) bad veo douily Livhed Lint . Sorat he whether oreo 3
Pe hate Wo bong 18 Oe FORW od ether one BACK
|
jue raced too Location lech
be jTn cook of dou Unked Lin
Atgration in Aloo vodeA droted
Od LOCH to nserd & New
Gubpere cx ort grin the Lrcotiom rock ond Lot of adjpcent
Areses A ond fi LEST Gnd Subpore tt Wort to Iwert a given —
“ew of wheuralion lis wodw A ond Do Am Bit) 8 gone
fod Grad we revere ype fowl ode N Shem te Avail fist, tone
ne \onoable New a“ Jreelp Voce al Ves fecatien pond then
i copy the doko Vite’ ivte fhe neds Ns Anat ise 9Page Nor? a
— Algestinre 5
INGT WL Crwro, FoRW , BACK, Fismb, Avoit, Loc, LOCB, iter)
: ATE Aveah 2 NOLL) then Corie ‘overflow / Cexit-
J ber News Aveik, Avod=Forw Avail anrofdeet= Men
BV If LocA-AUU eaiazestesnnn te.
Her FoRw {Nel = Foxt , BACK Ness = NULL
BACK [Fmt I= New , Fisnt New
% Edne :
ge4 FORW (Locals New ,ForW (Nerd = LocD
BACK CLOcRy: Nee 1 BACK [Neu] =L0CA
Ub Grate
Doubly Linde
@ rAwation Vie the worled Lut > ‘
APES Se fc. a. Jobly
Subpart Ver in to he woeled inte o ported t Linked Let then
Tem must be xoded As wrod A iB fe tat NFOLAT Page Ne) Lo
ws yy v2
we
vent
ADMeLgn ere OF Unhedlivt 7
Let Quist se a dotty Grred Lor oth a Node N blo wmode Aan 3s
Support BASSE ON! Vuaata ke deleted Prom Yre Linbed Crsts The
deletion ceed oP Peon OP tre neat porter field of node A in
chonged ®8 tatat por © ode Cah the Prev porter field of
node } wp hour gtd po that hs te wode A-
Wren & mode N w Atel ctedim (seine ts a)
Frum We wwoney sour te the felts Ns TR jae BULL Vora
we write falling Bebe to odd deleted nice te Aegiwning
oh Avak Bint i Bw foRWlloc] = Avait & Grek Moc}= Nutr
ee joes. Nails lor zBC con he Afford cameo isco
L Deleting the Node fatlnivg a triven Node
& Delete a vode uith ise Vem of far ation
3 Delete the foot node of » dorbly Lwhed Sint
J) Deletiny tee Node BMlnsiny a Gives Nodt >
Leh ATST be 2 dobly Onhed wn wenoy * Suppor we ane
given the ecotion 10¢ of Node N iw on dowbhy Lnted fist
Noke tat BACKCOC] ad Forw {tocy ore the Rocatiom,
seapedinely of the node ob! ch precede amd fellow notte N:
AQg crite >
DELN (DIST, INF, FokW BACK, Loc}, First, Losi , worl)
4 TP Finns NULL ther erate’ Onderflow"b ot
& TP wee BACK(rog] = AYLL then
set, Fost = Forw [ FaksT]
Ett
set Forw (ACK[Locl] = FoRWfLoc] and
earreteoed= Gack (FotW Ctocl] = Back floc]
IES Oecd
% seh Forw [tot] = Avail ond Avail Loc
eum coat
@) Leting the node coith give “item tof in fruation >
Suppers oe Axe given an er of nfoumation and wt wort te
gelerte fom dLivt the Fist Node No chich contin rtems
We Fred Ye Locotio- Loc of the mode N tohich Contain Hem
Troveme tne Lab wsing a pointer vorioble amd comparing.
thee with INFO Of PTR at tach vod ec
The traverieg iy Condimne ob forg ob INFO of fTR iv net
eaucd fs tems Thin [TR codain, te Lecadi on LOC of foots r
b> doubly Dnied Lint oe don't need te save ae
receding node of N- M i
aFINDloc (Dist, FoRW BACK, ZNFO item , Fist Lamb)
ES TP Fist = NULL then
per Locs Nott & Relen
% I} rnrolrustt siten then
ACL Loos Fusb 3 Redon
Sek PTR = For Crvst]
Reheat step S aite CTR FAVE
TF Taro [eTPT= item hen
eemlcO aa WTA Rebon
Ete
yO VE yo?
stk TR = FoRW PIR]
Set Loc = NUL
Goat -
WINS
|
EDELITEM (Dizs7, FoRW /BACK INFO, OC, Flawt Lert, Avil)
Cold FINDLOC (MIST, FoRW BACK, TNFO ,iterm 1 Fiserk, Loxt ) )
ColQ OFLN CDLss1, Forw, BACK, INFO Fiset.Lest Loc Avail)
y Exit |
(&) deleding he font wode_of donlly fated Sah
Te deukly Grhed WA, we cancel, accers te Joxt rede Ay
uring Lorb porter vord ofKe cs
To Pless Dank rode ) do folfoieg % ordignmentd’ once usten
Forw [sAciott) = Put & ForwlLerrd= Avoid. Avail Lest
NO yO NE
athe =
DELEND CHLTSt jFORW, BACK INFO, Fiask Lends Avoil,)
af Font = OL ythen want ~ Ovderfloa' A exit
Ae vue,
. ow [Fost) = NUL , /
z wen ay FoRWffiretl = Not 3 Dvoil= Fi rot
ond Flank = NWO R exid
ged FoR W (BACK fiesta] = NOW A FonwLletl< Avail & gAckLLost] AU
enh Avail = Lost: ss
3
a
y
> Exitela gs
Pe to halen fat te 0 Wade tint” Orne the fost
— Ipsite ¥ hock te the Wtadet rede i
TP Lak Cotext] = stort ‘Aveda that a Corcalaa Wade L262 ortle
Here IKK im a Worse ovay Uhich veld Be eeth forettr field of each
sed tof Hrrculer Rnfed Loot: a
Ay Tauting a crcl Mende Met ?
rele
Let cirst be o Circullon Ntoder fink i mntntyy © THs ally extern
Anov Bard LIS* ,abhly om aeration Mpro cers! Lo each rede ofttzoT
Aigotithons
TRAVERSE (CLIT, TATo, LINK , Stary PTR)
4. set Pp Tee Lank (stat 1
Re Peveat slepd 3 ond U chile LTR FS tart
Avy lprocers be NrolPTe ]
Ser PTR=lINK(PTe]
Searching in Crcados Helen Tat >
Thin algerie
ip pista
Clist bw a circle header Spb Vy were my *
. Ged Whe! 06 Ye pode Uhae Ther feat abptar ie Ona
HVW- 4
GEaRcH (4N¥O, Lan Start, New jLoc) j
4. Sek OTR = LINE forort]
2 Qe INTO CPTRY Fitter Gu PTA 4 Stone
+ Reed oh i
i rReb f ; obstilincce
a ae ae
ost shee tells
er Up LOC =A Tenention nw Corolla He ae Cage Nook
Hn Im Crater header Pint we Con mut ermenb
difRerte 4 poritiow Glich anes
CD) Arsention cd the Atqiving of Corceulod Heder for om eee 60)
\n
(B) teetion aftx a given node
DP Tretion Wo the verted Lint
Yo tarertion at the Gnd of Linedlor Livb-
@) Perartion ot the beginning of Crcaler Header tit >
Seppe or il rncbaated amd Of want to
“Vea” afte header node
pA oss >
INOF INST CINFS , LIN k,stat) Avail ite)
TH Avoi) = Nott Chen pont “ovedten "4 eb:
jurert
4,
Q Sel Nevo= vol é
Avail = ANKE vaid]
Be Sek INPOL Aes] = ihe
Y Set LINkl Neo ] = LrWkEstant]
S LINKCotant] = Neo
& Sat
©) smrostion fina given melt >
TW in alse mreilor lo Wwrertion after aguien rode tr iMgy Loved
Bort Me ory difforn ce i> the Laat weds i> how ting to the
piurt rode / header node.
[i decospe, yVb header Lint
Doe Aewynet cho-ge Weeden
wadeaaa -
INGERTLOC (INFO, Loc, LIWK, Slab, Avail, Loc item) PageNe? 1S
ATP Avoik = UL ; ther Orie “Soyerfee”& exib-
B set Neo =Avail , Availe Lk Uveild
Bet Tho Weed =item
M If boc =NOWL, tren
et LINK(New) = Storr Grd Start =Nee
Lak Dest = LIN toe} } LINK Cloc}=Neo:
SF Sat
2 cinadea lnhed,
©. Twertion at oxted lint >
Fontdy jx find te focatics loo of oo cich Whoe vawie by
Qe tran item
Ady ith >
FINalec (2NFo, Stanl) LI ktm jlo)
TP Starts WOLt , Pron net loc = NULL A Retin
> AF Wem ¢ TNFo Lobert) then LOC= Nuit A Retwm
- Sek SANES Sloot od PTReLIVKEStM]
Reheat step SAG while PTRe Starr
Of View C Inve (Pm) the,
| pet LOC=SAVE amd Retun
yan, WE VG wt We
6 Set SAVES PTR ond. PTR =LINKfPTR]
ca Set LOC=SAVE
Y
$ Return:
SNGERTC INFO ,12Nk Start, Avail stew )
‘4, CoM FINDLOC CANES) LINK ,/BLAA , Hem , Loc) <
a ANSEPTEOG CINEO ) LINK Stand, Avar® LOC then)pase Ne>T6
Super Wem io te be rooted ob the end ef a linked Vert
Mere we davon the Rios Jusieg o perder vasichle PTR:
Given at the end of Leech lint >
The boning umtinnts te org on LI k (PTR Stat we
Ans rome tre Teo one cen eS
ASer completing pravdoal PTR tp at ed mode , Yoon
per LINKTetR]> New ‘ LOW New) = Stor -
Ag Pits >
TINSEND (INFO, LINK, Sbart , Avoll, Iter)
4 TP Avoth= NOLL jther or de “ Overflers' GL exit
iy Set New = Avoll, Avot = LINK DAvaLL
% Set INFO [ Nees) = ikem
4 TY Stat = Nol dhen ;
cet LINk( Neo]: Stat od Sats Neo XL eb:
S sar PTR = Start
& Reheat SF cote PLINKLPTA] + Start
eek PTR =LINk fete]
4 FY Lok fete) 2 RSE ke
ek LINKEOR] =Newo 3h LIN K PACT = Sbaxb-
& cat:TW Bddein fen o Cretan tin find tag > EON
Dt» also similar te deletin im Bega Whedtid jhe or}
Bifference > aod node i» perntivg te hart wede-
There ore differed cane ©
4 Ddletmg anede Felbosig diver rode
Ba Delevomioe Ao che ui Wh gen Vow of 1 foumati on
7 eerculan Header
B Delete Me Lond note fron Moe Dredd Mor
Daeetns amore Snow (lfoviwg Giver node >
DEL (rst, IAPC, 1EWk,r0c jLoe P)
ATL Shart = NOW tebe Underfloo’ ( exit.
@ If loch = NOW, hen
nek Ghat = Link (start ]
4
ie Set LaNk Clock] = LINkocy
% Sek LInk {le C] = Avail & AvalleLoc-
Ww exit
&) Dhete A woke with giver iter of in Pommetion a
Fired, ot Find the Docotign Loc of the first Node N obich
Contains Mem ard slro the Do catiss Loc P of the node breeding N
FIND OL (INFO LINK, Stat, Wer , Loc ,LocP)ar ae aes say eetw er neta Ren
‘Ng te delete the Fret Nee J nichnicentane tea Je LT8t
orem 0 arent ea
DEL boc cat (ENF, AWK, Start, Avail, rem)
4 CoAk LFIND BML CINFo , LINK, Stont yer , Loc; Loc?)
BWP Loc NOU the ote “ier gw net Birr , amd ex
Y sed Lank[ ocr} = banetlec]
YU, Set LINKE Avo = Prot ek Avail=Loc
S Gar.
Sptad Ore
© ) ae pe tnd ote Gor wail be?
Ada mike >
QErEno Crtst, LINK, INFO , Shord, Noi)
A af Shoat = PdLL he pet Soe
yy LInk{stot] = BS ren poont™ Concur ae Lor io
3 SAL SNts stot 2 FTP = LINk(Stont3 SNe
Us Petar ser S hue yan k C pte) F Start
GS: Gex SAVE=CTR APTR > LDInklrte]
Y=
TE LINK (e TR = Start then
pet LINk GAVES= Stok ALinclewMms Avail Q Avil= PTR
4b Gar
# Seanching rw Doubly Liv Viwhed Yot >
QUART (dLtsT, INFO, FORW BALI, Fiswk , Look | Leng, Loc)
Je TL FodA= Now jhe #psind Lod inently® Leak
R Ser PRS a vet
3
2
Reread tonite LEAERER For CTE 400
ay ingot wd = Veew then ee
mer 10C = ere wr ees é ‘
Elet is “e a eal : 5 ze