Download as pdf
Download as pdf
You are on page 1of 154
Module “14 0 —— 1 Daka + Dale ts collection of Valuer. eg the dala of a Medeut include hrs ven, Name, Lemester, phere numbu.. whore addrert gochen, Adve and dab dan Le frat name, and Name may hove middle and Lote nae Aerdenk ASS Nome em See “Addvos pheno Pike — middle Lert Hrrak aren. Dale Weuekere ts dhe Logical @) mathematical model of & Peshales pr ganization of data. hoo daln is exgenised, Mored tn mem ory Diba pchure + be dptakions + The choice of dake Afechure cs bated om beo deeloe. 4 mure be ich enough te Carry He volt eoehips a) dat. 2. at thou be Aimple though 4 oflecteuily proce, he dobe There are two ly pas ef daln ddouchure (1) Hines Daln toeeture 2 SP the — olempentr — 8) “he dale ali ferent any Aequente then ib cA called Airco dele dourbure. Srquente Can be tmed in barmg 9 dequen tal weme4 locating §R) veletivnsp Yn the cheayeuks Veprerecct ed with fhe hep 4 Poinkers. P2 es Avoug, Stncla, Buewes, Linked ligke . (2) Nen- hiner Data Mouehure 4, This Houeheve ee uged to vepreseut hievarchial between obsuyeute- “ mainly relat onghep a Frou, Graphs. Arteaga s An arreg cx tinike collection of elements Akored 7a adyatent memory lecakiong. The number of elements +> be used are mMontined ae index tually Yon ing dumm 0 lo AA} wlere oc Loe bound and N-1 vy Upper Can be 4p ad & Malk- dimensional “Bynkan bound. Arrays Daln- tyre Arvo name [ index) = iy Ant AC); cha = 820): fpot FLIS); af Als)= ] 12, 20, 30, 4, Boy then in the. Avro ib & thown at AYe) AD) Af} ro Sahaeripl | in Als) _AlW) pt | Todo A: | 1 20 ao | ae | So tig pee ae The elements fn the array are Atored — ¥q Congeculive Memory locabions , serkng daerm deme. bote addres. Addie of arf elemew of the ony 6 Caleulabed bg using dkmula, Addin | Dlx) = Base Addren + WN [k — dower bound) BA? Joo Joh log ne Nb e EBEEHEeEHE Pe Tete [Te | Alo) Ato Ale) als) ze apps. bound Lower bound Jn commpuke Addn of Als] where Ke® and bose Addren = 00 7 Als] = loo + 4 [ 3-0) Nerd Length (Wye ( = U2 Lowe, bound = 0 ee uyppu bound = 4 Tt che eler cubs fa the avroy are plated in vows ard toloumns hen ik ad Anay. Ft is alto called Habtx, of ordeg MXN { Too Dimenatened A a> Arred Gon be Yoprdeuted ag Nae _" : : aaltehears and dipention Rood} Jo 20 30 Yet: dey) Row!| ap Se bo Sabon : Dela type Arwosy- nome (Row) [eat] : “4 dob AT 23037 5 Pa Aflaj(s} Nil) have g vows and 3 eeleumny, Srikaligahon of — ALIPs) = } te, 20, 30 40, 5e, bos colt | Cola J l | ele — Firyt doomd Row 0 | to 20 30 wr now Row ho So bo Te ged Arrey elements Can be Mord ae Row -mag Bde CA colouma - majR- hades. Rew moj Bde 3 ‘ Apollo) ; ee afciiy A ane) Atle ne talournng to [ao] 30] bo | 5 | bo | Base pre ee, TB ie Aen Ato” AVA ei cempahing Addren 4 any eleufeut- ts ALP tk) GP Conte Add (Ate) = Ur Eelounn= Majd Ades 3 a — below, Ati le) the olenjeu element aN Row - mag h Ades. «Base Addon + WON [fi - Row Low: Bound’) + [ col tov-Bouf) addren , Joo + » (2-0) + Lo-21) 2 loot Id bs ave Mord pee ae tof lo® PBL Afolfo) AWIfo) ALTO) Alb) Ale) file aie yo 5 Lot te velo colt ns 6 to Cornpute he — Addvena 9 elenjeut Atered — in Cobumn - mois Ader, dew (ALs)EKD) 2 Base-Add + ual Afoyli) = = loo + B = lok (1) Traverse ( 3 $ (2) Srgert Single ; (ay Delebe Dimers SA (5) Search x elie) +[7- 3) bow joo + 4 (2 (4-0) + (0-09) ) Trangpase Da ag Adcditen ad 3) Hall plecaken Aros ‘ , Pe oth et py" ecko @ K ° | alo [afeyt2) | on 0 ate hing 2 eel Lob ws atgume Row 4 fald foe] ald ld ali) [2) base addvew = 3000 3o0b 00 | 3e 10! Abt -o Row 2 fafa) £01 BG aot} iat cla: wl zoe — + = —ubl = 2 afsfa], 4 ——— ubee to tind out — Aocation go ¢ (fb) + 0 # [-dba) ¥ (1-0) + 2 # 02-0) foc alil(jl= BA+ (uba-2bat foc af 012] = 3000 + (a-07+) ¥ 3004 b+ 4 = 3el0 which holds the Pornters ¢ A Pointer i a Yaxiable address of another Vartable- Deelation dgakax of pointer Variable dala type # Vorteble - name ; Sf a & a Variable which hdde the Value 5 Hor ab addvex to00, that can be Adon phyer cally a Xx 1000 a do Atore tha addven — er0, eer eee Variable, declared as ink OP ; Ne need a Pointer pole pa poinber Variahle lich shores the addres of tab eaen Vaviable , ty this Case os %- Pe the PAogram Acgmeuk a ae St; mata t) i looD - Unk 42300; ; Pak Py p= 42, P }o00 Paint? (# Wadd yd" tp ¥P); 5 oe ° ; ulpuk = 300 1000 Ben Relatieamtp —bebseen poinker and — Arrays The away elements Can aleo be accessed Maing poraters. be by Ming deve derencieg pointer. ger vePerenciag. See dereferencing : fal) iat jy, sholic tok al) = $602,143 4 fat ¥P ps &alo) ve @ fa ( jeoy J4b; G44) 2 pratt ( * 4d, 4d", J, ali, Pett (ea rd" 5, ¥ (p+ DY } Pactt Aber oudpuk ° 5 o 8 ee: e : be both give Aame es ee 2 2 ankwer 3 ete fa acs pe alj) % dame 5s 6 Sees a ¥(P+9) 4ame- nobes Rplsd, Sjlp) and (pri) ave Gparse Mabix: A parte mabix Gs a matin sohich has Very des nm-gero elements. be Mabix with more number of 302 elements, eam | mere than half of the Age of The mabe ey {2Te[ To[o] el sparse — mabeix j2fehT Te Nm sparse [ bes few no of Ber J [ : : Aparse mabix o 1 .o [2 4 °| Non- sparse mateix 3 1 oO Yo Yepreseuba hpavce Sparce Mabsx Representation 5 with mah, ne Crider — Non- ero clemeubs along ls Posibion- P10 ang tlement 9 Aporse mabe 1s dobined _ the triple < 20n, coloumn, Value > « Fa: if dparse mabix ts [? 7 2 0 ool eo 0 then 4parse mabrx — representation ts given Os, we col vols ale) 3 3 3 ati) oO oO lo afzi| 0 I 3 alsl 2 i 1 Tn afol, rou Value 3 represoubs ne of wes in Aparse abi col Vole 3% vepres enks no ef colo mnnsg ta epav7e mah Vol Velue B yepresenbs fe af non- 30 elements | He parse mabyx- fy alll, row Value’ is = 9K poitten of fo cel yalu ‘s és col i HEC Vol a Value 4 to pn ® & 4a! hlsbe Apavse makst representation of — below sparse Matrix ° ° oO I o © o o 2 0 ° @ o >~L@® o o @M »o Sparse Mahix — represenbedien ° Q@ Oe ts, Atnte We have g Nen-geo elements, Ne wil) have Nine vores IN Aparse~mabix — yepresenbation. Yous tol val ato) 4 x 8 ald o i Hl ale) ° = als) : : . atu) t 4 i ats) 2 2 fa ati 2 4 ! afa)) 3 ° 4 alej] 4 Pyen Hike & pam 4o check — wohether the given mabsxy ts Aparse maby, and representing the Aparse. mahix- include < 4deltorh> include £ cmiv-h> oid mata) ' ink ff, 4, 6, tore, doo, alwytisl Slot; int tfre}Lw] » Meo, N= 0 tlrserO 5 pointd (venker the ne af wos & cola\n"), sand ("Jd id) Sr, $e), pont f (* enter He — matrix\n'); 4A liso, bdr; tee) ' £8 Cjeo; jks 5 dlont (" .4"- AaliL i); Calas 6) 4 tons: 5 che 7 ++) fC & >((rxed/2)) (or) (L > co) i Prolt J¥0 Mabie 8 dparse et) eal Ib y che. Prinb (* nod Aparse mahsy \n"), LY PoinbS [+ EO" eparse Mobs « YePrecente hgh) ¥ 2 6[m) (oe) = © Sim) [iJ = ¢2 S(m) [2] = CO5 a (4s 0, tar; i++) ; 4A( foo, Goes J+) 1 it( ately 4-0) t mat) simifel= 4 gremlin is stm lad= ably y 4 ropresenkation \e"); pants (¢ panting SP npacbsx Jal ice, teem, t+4) i BAL f<05 1480 ye : pantf (* 1d ‘ g(a i u \ pros (* \o"); Print (# Findeng Framephe tyabie \n"); SAC teo; cee my t44) : FA gros 422 prev tray. stad lye 3 Ponk? (* Tuangpde Habhx prinhin ie) FR Teo; Leas c++) 0 : AAC §s0; Jxem; Jt 1 pnb fe ya ¢fe0lads peat [*\n'); aneps Tronspae tf parte abit Repesentestion + A mab wolich Sphetned be Anker hai and colounnnns ts called “Transp ae 2 4 yors maletx- : - a eeeee eH ap oY aq AS i 5 | then Ale a 2x3 2 i Posnesel} BRD af Aporse Hoksx 04 2 3 2 1 0 ° 5 then parse Mabie represen te Hen % 3 2 4 o oO 2 ge } ! 3 ° 2 i | ! e 5x a Transp 2 af above wyabese ES, 3 ° ° o 1 Te 3 O° 1 2 © 4 2 3 2 ! Dynami Ye Hanagemenk 3 fee emer as eee Ne have 2 type of Memon managements [Allocations } SixHe Hem Haent 2: Danamic " 1 SleHe Hemeny Mgmt « af memory # allocated to The Variables dusted Cempile Hime Hen ib is Called Adnbic nyemony allocation. tq: tat afi; fak PS Disodvantegs: Ih Hemery dpae Ficed duns Cam pilation Fime- ‘. ik Can't be allerwpsl. 2. if all the yemoy allocabed 4 nok ted thon if bead, to emery weaubonge can} be tacrested faker, if Ne 8. Memon reqcre to be Hanagemeul s Th A the precems of 2. Dynarnic Memory allocating stemony devin execution [oun Hinge - FL wes Predebined dunchens allocate and Yeleate. memors. Different Memon Mygenb Junchens are b malloc) 2 Calloct) 3. Yeallees) 4+ Areety (iy malloc Ot “this Punction i& Used 40 ablocabe Atrglt block of memory Space hosed om the of babes Apeci bed in the paramebew number P16 Agnbax* phy « (dota-tyre®) malloc Cig), wohere prt = pointer Variable of Tipe dale Fy pe dala type « a dye. of lake Age = number of bybes Veg ctred. fy: Job ¥ ptr y Yh; phe = (tak ¥) malloc ( Aige of tra); pt = [ink #) malloc ( te) 5 om AaccersPul allocation of memory, malloc Yehunt He addven of ett bybe of allocated tpace. te 4A hr phe (int *) molec Cro); gs tee efondee [cera a plat Free Memong Ltoce had bicteuk memory os there, malloc Yeturm, addves of frat bybe ee olo to pty nor Auccerchul, then malloc vetwru nul} « el Tf See ee Free Med by deme fe meme other rqm Aince pate 6 mk there. Fh. malloc C10), it Yelury NUL fo pled. Khibe Pg Jo illusbrabe — malloc function. fp include & Hrlio-h> Ty pelube < atdlabsh> void. maint) i tae 2,n, ¥ph; part? (* euber on") dean} (8 yd) 0); ple = (int *) malloc C Age iat) en), paintt (+ enter a elements \n" ), fer (feo; fen, 04+) Aeant (4 Jd" phr+a) Pont t(* The aiven elements ave \n"); tor (ico; isny 144) potbd (1 1d" #C ple +i), 2D. Calloc()3- This function is used to allocate multiple blocks ef memord and is metals wed fe arrays: Agpbers Phe (data typa) Calloe ( a, deze) where ply = poinbs hdd the: addvew of trate byte dake. tape: type of date n= Wo of blocles sage * Aige of each block, & if we want 4 allocate x blocks of babes each then, prs (ink ¥) calloe ( © 10); Pre fo, above Mb allecaba 5 & lo = Be bybes of meron fm bel (ee 2 1 Phe € Five ghd flo 3° block —yth glock == tA block block tk of of 4x0 10 Aige eae totally 5 _bykes - Re ereree er eeeeeee gee Eee EEE or succesdil allocation colloe Funchten byte ptherwide — Yoturyt = NvLL- rehumn Fint Pyens Pym do tind Moximum of NN num bers Wingy dynamic array: af include < 4bcli oh> H include << £tdlib h> Void maint) ; jt Fa, Ly pantt ( uber adn’) sont (" yah 40); ne (tot ¥) Calbec (0, 4ize of Ciat)) 5 Point (“ enber elements \n") 5 fa (ico, ten, P+H deat yd" Sal); (or) seonh ("yd") atid; ta (joo, fon, Pans C+ +) boy (fers ata phlnn Hh. pailion af jedy freee ebenpeul> m9 @ Pott C Lege cleyenk Yd Pound ate petition ya" ali, fs Free lar; 5 Nokes aft) & dame ag *la+2) sali), £10) and (a+z) are Aame- Diference bla mallee and Callen ¢ malloc ¢) Calle 0) J. Allecakes mulls ple blocky 1, Allocedree Hingle block of of memory , tach block, memory: with dame ize a yan 5 2. sgobex pir 2 (daba-tyre®) mallec ( ple = (date -lype*) Go ILoe. dined; C nt Aige) 3 3. Allocaked pace vf) nok 3 Exch hybe «P allecabed be faitialiged hye is Toittoliged fo 0 4g. Mere expentave af b. lexe expensive att initialization of 3670 5. ley Conventen 5. Mere cenvenienk b. Though The Hee etemong g. ER femoy ayoileble (3 ia not cnbigous ib allocate emnbaous -then ol ib allecaber Memory. 3. realloc() ¢ “The Aize af allocated memons Can be changed uti veallect) fe city + tatrease (8) to decree: Byole : phe= (dake type *) realloc C ply, #3e), + Ply és the pointer +o a bbek of previo allocated — memory through malloc) 4 Calloc cy + wige & new sige of block wit the enisHag memory Can be eukended then Pie Yalue vil) nek be changed x ig tHe memory Cant be exkended then New Memos fleck & Creabed and the Cebenks of previous block, are copied tp hes blocle & to reallocate ple to & babu deen 4 bytes pire (Gab *) Teallee ( ph, 4 ¥Cuge4 int)) Novo phy qs Gxrraes babes 010 012 Terk | w | 20 4 a Previondy used bs diester alloca other rar Hin end "4 Alber yealloc Ne have 022 922 poy orb foro] be Pe] > a eee pt Td wd by ofler 7 peallocabel memorf hy by. vealloe after veallotahon Parr s Nake a co pgm Ahowsing usage 2 veallocl taunchon om Characters ct include <4tdich> Ho laclude. <4bdlib sho 4 trclude < aleing ho oa Void = money @ i char “hs 5 ble « (char®) malloc (10); weocry ( Me," Compuker"); Nop hs = (char *) reatloe ( sh, 4e); Sleepy ( Au, "Computer Aciente and Engineering); hy tec y 3 Ths Pinion ts used to deallocate the allocated block of memory Hina malloey Calloct, of Yeello ce functions « Aagnbact tree Cpl); Tinbeduetin to Dak Shueluree s Daln- Shuehire ¢ Dala means values, Ad>uchre meanc the way the Valuct are ovganiged. Dake Meucture th the of how otiiently + pilterent type of dala are collected and Atored tq Memorg > Dale ts orgamized fa memory , Dale Can be rvebived and mantpulatedt L pale ibems ae logically = labed atication af Dalu-touchere 4 2 type 4) Ds (1) Primrtive Date Mowe turts (9) Nen- primitive Dale Mowe tures Pramibve Dobe Heuctures + Te be mantpulabed divectly — bs Called Primitive Dale data Abouctures that machine ingtyactons ddrecture » ey: tak, dloak, char, double — pointers are wt to detine detterenE dalx Abu claves Nenz primitive Dale Abeuchures ¢ The data abuctures that Gan't} be manipulaked directly by machine fnetouc tung are Called — nlm- patmitive date structures ( ) Compound dake Mratlures. bq: Aveoys, qoucturer, Urals, quenes, linked live, tree quate, til eke. i Tere ore 2 type of — Nen~ primilive G) Linear Dala Atouctures @) Nm bnear Dds Date Apu ttures fons pe marge) || bar ry oda ithe rst a ae Data- Sdouctave where hg Values ave tored in Sequential manner ave Called Linear data - Abructures. Linear Data Shucheres 3 3 The Ege Ariouss Linked links, stacks, queues @ al) ali) al) af) aly) als) —> arog Ta[ sal she] —> avn elements op 19x 10y toe IPE HO > addres E] Non- Lineay Date Shaeturee The dala Shucture where. saci eee alee pre Called Men Linea Dale dhacture. £4 Tres, Gasp fol 10g @® 5 Abstract Date “Yt 3 An ADT %& & mathematical model af a dake atrucluve thal pecities the type el _data bored, she operations dupperted om Wem and the types af parameters e 1 q ake operation’ be Apt apna wheb each operation oO dou, but not how it does it- _ ADT Aeperakes Implementation trom kperifvcatien. cabs a daka type wohete Yeprtentation is hidden Deeg nok Wank cliert 40 directly manipulate data pe &g Apt fh Shacks 1 eperation is LIFO ) posh: add information to dalx +bachure 4a) PoP Remove. the mov recent Teer Tntertien $8 Methed 2 sb Aemilay be plying thes Gale rterbs He Corvrenpenli ais enaek Location while picky hi WME Compares ad ebewjeuct Algettina + Vol tneertion At (iat al, 3 ee tok U, ikem; jen) t++) 4a (tt; i them= alt]; Garde, Ce eboert- — tabo the cbemeuk fb rev iotag elenperut 4 n) 23-1; . (them < alj) 48 f»=o) alj+) + aly] teers ¢ d 4 alj+i) = item, Example s 44t dhe lr DD 20 fows b+ feo —> theme afo)=b, fr orbs -! item iweaf-) x 4 aljr)- iteno afoj= tb fe) —> theme afile lt, je J-[ +2 nz tb x => afi-i7 a2 abel heme @fa)= 19, J 19414 xX tee => afa)-'9 x P25 “3-2 thems ala) d je 3-18 the _ Yes xX 24 —>@Q a a fen 2 ae lg be gez0 ® ats = 4l2] 2 oalslsl4 3 jraddet aco ov ae 1770 Gayot tessa ae ae Pata ae eae afi]- ib, ge 7! afand= afel= a => Peete eee 6 ia jal | F | 26 | Io ji | 3 19) 7 {20 | : | wt | [3 | \¥ oe JooP + wleb lerminabee Quick Sort? @0 parbliming Aik + Developed ty T- Hoare fa 1959 Wethed 21 Celed Pirate clement af Avoy os — pivol Tnikalge tand {fe Fete ond fave elements f the. away raspectevilg- 3. Incvemeu 4, unbl Ali) > pivol » stop ty. Decrement 4 unhl Alj)< pivek ; stop Reet Eachange ALi) and 414) ¢. Repel atepe 8, y and t a x unk] fej when £ Crohee f be exchange Ali) and 7 Pive abemeut . Algevithoa Ouicksat (A, 18, vs) Time Complenty But: Olnle ip ( 48 < ve) i o i : f- 18 je ve fivok = LB while ( zep) while (C Ali] e< Al pivot)) 4& (<= v8) d= i4ly whi ( ale) > Alp vet) defy yy (ie 4 7 2 Io y 2 94 6 3 @ Pik feo t 4 = 5 + 1 2 10 yo4 § 4 7 ins age 5 Ft 1 2 b 4 4 6 3 shop rere wink “qi a el 5 Gt 2 w& Y4 4 6 [3] : e 3 $5, slep exchange Le J decrementing J Lg 4 x 3 l 2 Io yo4 & 4 cae J 5 3 I ee oa Cte 6 aq a i 5 3 1 oH loae Heated. 6 of in J KS, 5 3 lo | = ie ! 2 fol 4 9 & 7 & Temenking ¢ e J Pivot oo £5 J 5 k + B&B FP i aLgap] then exchange ale] and algep] 3. Compare the elements allt] and algep+ aad yepea this %4 Hid bing the potion, until He bate cleyent & Yeached. Algesithon a Vord shell 4btr 09 break, 3 Cm oul of K loop ; ge ater gar): alktgor] alk); afk) = t; P20 Ey: sob the cleyents given below Ming hell ace at, aa, It So, & 3 L 24, 64, © als) | Afel] als7] ale | al Pee ice : i + aa| |@ | 6 &) 7 | 2a | 69 ice ~~ | | | le frees , @d) ore So a 3 © | 29 | 69/8 eee le, ' fe) | 50 a) BF) aa) @) eae i 34 22 BF Ok y No change I {| i 3422 | | 3 1 | @i wm Gi w pam | 79 fer F | | 18 >2 exchange | a j i 7 I@ jt | @ iow {ie | 39 fre [rr peas? < Jhange | | 3? exe! a 4 2q (69) = 2 | 1 3 @ ! @H) | ?* s change jee | Sopat enene~ | 5 @2)) 24 69) s a ! 3 | 3st Ue | ide er | HEH a | 3a | re | yo 27) RU} 69) © | | | So p29 jenchang e | Hea tae a | GP 18 @4)) aa} 50 Pea] = | | 37729 enthan lo | | | Fe lal on 24 a ag | te aa @H | % 1€)/ 9 | aa |No peng jie a| si] 3a | aa] te | aa] 22] bj 69 1@) i | a |So>5, lenchange aii | 24) 1@ 64) |e "( ettte eet ; GY | 22 | © |61 | so 31 >5, eXchange i [s| @ a) 1e | @B) > Hl! | 2 | | | << — 947s, * peehtge ail >| ffl fa [ |b o pes 2 @ | D 3 5 | 1e@ | 24 | 22 | 34 | 649 50 | { } | } laps gee abl, extha | i | | peat @® ot 5 | 18 24 jaa | 39 | 69% Be Bat] No change | SI | we pia @ & le 2q jan | 34 | 64 2 | NT | ly a 3 @ @ 29 | a2! 39 649 5o | No | cha ies ey ee 5 é * 6 | 28 | 22 69 5 | | | No cha | | 2) 3 5 | 18 @9) | @2)| 53 64 5 | | 2a v2a, exchange a j i 1 preretneee 5 te an /€3)| 6) ba | 6 | No change | 2] 32 5 | te 22 (39 @D ep to i | No change | 5 >) Hel le les 5 | le | 22 joa a @) & | | eet i 64735) enchen | a2} 3 5 and Pars 4 Hae | ie Ptek-o _ hace ep ce stop al shal he florals paz R Got 2 Developed by Havel We Seonrd io 1959 Since Ne are Aeorkin deumal numbers (havi base de) atume there are fo buckets — yang! dumm fueket o +o bucket 9. eg Methed + Methed 1) fend Aavgest number of ‘th given dis and, in the Largest number, find ne of degite. of Ne of degits are n, Ne ned mn pee to Kork 2) Stan each them (nam ber) 0 the dist Obtern leave ign bicank dig day ds insert this number tnko qe buckek dd 3) After mouieg all thers — tab Corres prncling bucitees access eaeh uckee farm doin and plate ik in the array: uy) Reped eps 2 and 3 fer rent head Aignibicant digit Nokes “fo obbain lead> Kigniicant dug ib, Ne have to do th (modulus) eperation wilh — tot where 2 varies baked on Periten af digit Ae vant e4 in fea, t gtk 9, Ne do (49/15) 4 10 fo gtk & hee do (489 / to!) 7. 0 to ge Ae do Gea/ ie) % 10 10, Is, |, 6, © 100, 25, 5 ® Examples ws joo, so mete all ig) numbers the borgue Nlo +o 3 digit by appending o in the beginning ko => O10, O18, O01, bo, 005, 100, Poss 43 get dea dagnit Cant bik ond carregpending buckel 050 108 025 060 00s O10 001 Ey [oe ({[2[3[4fs,¢la] # | 4 Arrange dhe. tems to each bucket fren bottle, OOl, O18, 005, 025 plo, ob0, 100, 050, bik, te wolich & Pom 2: get next — leat Age ticant in lens pation and move tp tar | buck el 008 ool ols 129 p10 025 050 obo Pp }00, ool, 008, Pars 3 p25, O80, 060 =" gis p10 pos 201 Joo Te tv [?7T2:t4+l*leli,ttia fme Complenite = alnk) "1 Salmon Paha oa Module =2°° ie -O Slacks % Oneness staca + Delinthen, s&tack Ye preseviation, Prtmihve operations on Stock, array wepresen|ation of Atacks, Application of 1) DA- Virsabk top refox to top element steak 3) Away 430 Sree ee tei eta 24 Fo : i sb Le | 20| 30 ru ce : eae Vise top + The Voriable top — changer dam 0 te bige -} + Sick & empty when dop = -I «gtk & ful) when = bop = Agel s Tn dived keige Aoek ababacton, the Lge vemoing ame: when: Fop beternes mor Aige. mdmnié-—iabvteaiehery” kage de Hes - 2 fpeni. 2 wilh bes Ps doubled. Applications of Sheth + ghauk is wed tn applicahon 5 Arke eee 1) Recarcion 2) Frbonace® device 3) Towers § Hanoi problem 4) CrnVer dian of Caprestiont P 5) Evaluation of paebie expression QO) Recursian # Recurhion ts a method af Cabling a function by ibself ke ik enables & funehon -bo Fepeat- ebselP hevordl times “to tolve He ivenw problem Bore cae (> “Teietanaking Cerclition cs manele There ave a types af Yeoursion ni eeeraaen D) Derek Recarscon 2) Lndiveet Keeursion . prreck Revuvtion + A restive fonehion hak fnvokee “elk & Aoid fo have direct reenrgion- £93 Finding daclorial of re webega. : AP include 6 thelioh > maint) 7 4 gat dock, wa 7 Back = factorial CH) : pooh (11d, “Eactwsal, 4 hd wna ®& dct); Pe dat Pacbrial (int 0) if(a==e) ae ait vetun (7 Direck Receardien zal ye hun (a ¥ fact%r-19) ; j aihen 4 -furchiew Cole other Faehen tea atea ge tae the following Abeps ave petermed | é ) operating Kepibem (os) trancfers Ho. combo! to he maint) with rereon addren 40 thet after ene bing he bly of main -funetivn, te Conte) 4 Yokeyed fo Os — 08 < > aun) Q An achivation recerd creabe| PR each Lane ton been Called wluch Corents of paramebers Icke rekon addien, local Variables, Pieviow Peame poinker. The enlive gelation Yourd & poured into Unek- y me He elon Velen is reharyed to main, the crvrerpendleg avlivation yeeros Ore deleked bem de fa Fetetwtal.C) below thon He vundiede- rare main Cale Pachon'al Ch) 40 “ihe stake bent alle a wane Fhe attivation record op matu wrowon at below 9 » dictovial Cy) & — enecubed and th Calle factorial (2) Ao the Corraependlng artivation Yeeerd & thonen ial fe 4x facts) a + fawbeviad (3) Cale Fackntal (2) ax Facterel (2) - Ads Rect cA aabial (3) oe Gy srg | Rabrial (1) , Ge other) Pacbrrial 1) Cals techriaticy 7 since Pachorol (1) =! three po hee Called fanthion faebial G)- A Cempubey Bxted ae Tela Jo dachwalla) ond do oq = 4 xsl 22u hang myn en T 7 1 7 | is RY Ble .. cab 2p=2« | cau v Gindirect _Recurdion ¢ A, denen which — eenleine ; assec ty another funchion which i turn Calle another fanchon and som & Called tacireck- Yeoursien But “this ~mpethed ery aiffiealt 4 dangroe dogeot errdX- i v Tau EEE Void 410) > Void fat) Void 46305 ? ' eee toon y fa0y,— t d30;— } F105 5 © Ancther appbestion of Shack in Po ing Fibonacc® Lo Numbers ave Aso’ numbers 0.4 vie. Tn Fibonace? devi dhe devia of generated, by “odalng “Bum ef Previous exceph ee numbérs * Po Jol we (kee: hoo be” tite veswraive | debinihien of © Fibonan? Aevies- Flo) = 0 te flo Af Ha pidleae Cea! rOny=l tfoone) pos FU) + Fle) = Ito=} els) = FOV +FOD= pa le2 ety) = FO) + FG) = 24-3 FOo) = Fln-i) + Fla-2) > General Care A genthen 7 tat oF (ink on) née, hoes rang nos 40 eee at (n==0) iy aoe Ae relen 0; 0 + ) - _ Slay + FE) 4 #2) if (Cane29 J~ retin 1) Jia Hl) 470) ~~ rehon (FO) + Ff (n-2)) 3404 419440) +42 t 1 + orth) tle +48) . 14 e41do +554 Ho t+oFp +oRIO + Toys f bs The third applicalten of stack ea! SP > pcabe Problem. Tiers Fisove of Hanst posblomy © Theve “are Thee ps pa te Pee hug A, Band Co The different diameters of nn dises placed one above the other + Peg A 8 bouree: are Peg Peg 8 & inlenpediake. 0 ~Femporouy . ; ah Pq ct derinahin pepe 4 Te problem & fo abifh all es fee peg by moking Me of temporary pegs Te alee fo be foloved whi teanedening the der are moved at a time from ome Peg ay b one dike ib Another req . Qe Sinatlar dsc oe ™ top of the danger. awe ak ane time- 3. only ame Peg is ured 48, Aoi tnhermediake diac. a te tnidial Lek up cs | L ; Peg A (Source) (t em port) jonsfering all duce to PS from peg A, rye Pee (pukinatien) _ Dnpkmenbeion s Eebeen Eel ILE qo Bev! Move (n-1) disee fer four to temp. cd EF oh _t | ths (an be dene by calling tune tien transfer (n-1, 8 4, #) Slepa: Move ath disc trem — Aoarce to ~ detinaion Lda cb Can be dene a6 pratt [* Move dese V4 bem this ye to Lela, % 9 83 Shep: Move nl discs 4 diem temp to = eshnaton Source. temp this can be dene Hi oa ae teansher Cn-4 b & 4) 3 FP one The move §] “Towers ef Hanot problin ate i) Hove duct trem A we C ae | ere xD Move dise 2 from A cee. We ch! A B } 3) Mve disc! trom ge fo B aos fe Eee S cc ») Move dacs from A be 4) A Move diet fem 8 oA EEE ec oo A 8 2 € + o¢ Move dcr bem B i ink ony PrinHf(" euber no Q disee\n") san} (*yd" sn); Francher Cm, A’ ‘B') *e); 5 Word transter( int n, chor ¢, char +, char d) i af (ne200 redum 5 Utvanster Co, 9, 2 13 af point (* Hove dike Yd term Yew Lt, m8 4; } j tants, Cry & & 43 4 Another application of — Shacla cx cmveredon of Lap Yoasions Z Expresion + The Sequence af opertrs ond operands that Yeduces to a single value after evaluativn '& called an eaprencon. & ath, ab, abt Represanbaten of capsenions ay the Acanned dine! is epeval& then ays if Apnbel = C! theas parh 7B Fale stack mbel = "3 then pep all mbols — trom Bee ayy ace Fe patch Agar ~ inkl ‘0 Cemet in Hoek, and Hrally remove ‘ce frem dark pnetio oe if Aymbol 2 Foperal beh + *®% 1, a A) then check, and Crmpare precedente 9 seanned. Ayobel and 4foek 4yabel, Lal Lael ibe! precedence. 3 Atanned fol eC Sees Pop mbt darn Adak, Finale pork The Acanned — Xymbel 4) Repeat tkeps 2 and 2 unk] ond of eupression 5) whi stark not empty pep and place He operatny in. peehix expredzcon. inte back Fa: “Ceavest below tnfiy exprenéon do paths expreucon. A+ (e¥e-(rAre))/F P16 ate (e*c— Cae) /F 4 - habe exp canned, ack Pave Bix | agen bol contenba Expresscon A beg A i o+ + A c +¢ A 8 + AB * +0¥ | AB +c¥# ABC a +¢€- ABC : +C-€ Ape ¥ +en¢ Abe € f i +C-C€A ABC¥D is +C-CA ABC #¥ DE ? +¢- ABC¥ DEA ia aol ABC ¥ DEA- 7 +/ Abc ¥ DEA— - +/ Abe K DEAF? 7 Bo ¥ peEA~F/ + a pat bee Expreasion = ABe¥ DEA] + Convert tax exp (CA (Bc) £0) AEE) | without Algeréthon, : CC A+ (B-c) ¥ DD AE + F) (Cas [ee-Y>) 78 +F) CC As (0e-D¥I) A e+ F ( Asc-p¥ Ae + FP) ¢ [avc-p¥+ EA) + F) ABC D¥+EAF H+ Eye: obtain pattx of XAYA2—M ENG P/Q XAYAZ-M4N+P/Q XAfyzaJ—ngen tr /& (xyzaa)-N+ p+ Pp] @- [xy2ar] nena (Pal) (Siete anaiesceretertael [xy2nam-JT+N + Pras) PO sete sscceaeet [xyZAAM-N4) + Lpa/d XY ZAAM-N+ pal+ & The Luk application of Shack 8% = Evaluation of pot bx er preseion - Agorithen + } Sean the mbol from lefk to veght i “4 fin the. given povttix expression. 2. Th the Atanned Aymbd ° vs an operand, push +E om tb the Stock “2p He” beanned guahdl ix “ani ~ operator, pop fom elements fen the back. The tivst popped elempoank a operond2 and Second popped element rs ope rand 1- and pwh the resulk on fo 1) Perdorra the operation Abad, 5) Repeat above procedure Hil) end of inpuk 24 encountered. Ey: Evaluabe fhe pote hx enpremion agg +1 $74 | pat lx Expression agentel opx} opt Reale Sheek ‘camned : on FoF bsa-s¥tipa+| 6 | 6 3a-5¥+1¢4+ 3 630 Q-s¥41 694+ 2 Peed -okei gar] = fe re eae seagate] o gle HtIgt+| * a ! tee item Be tidat] + x ee eee ecte ae andl i nod das ¥ 7 nofugteu fu ae uo . + Ff y U+y=is | ie ignmenk Acaigan Evaluabe. Lopresigen 256+ *QAYS Teratien’ VA Reeurdion 5” ce : : Sheratin ihe : |. Dhevation eaplicitly Uses + Recursion acheiver repehien a repetition -Sfouchure through yeeursive funchen Calls 2. Thératton terminabe” ohen od Reuven terminaber when loop Cenclshn Pails base Condition & eahated. 3. Sheraton Keepa mod gh 3. ib Keops producing eval Counter Value, unt! — loop Podbante q problem until emditien Foil: bose ese 0 reached &- Reduces . processes pe 4- Gncressez paocesaere opera eating time ting time. a & 5 Memory occupied os leas Memory ‘gece A Mere. Ouenees A Quene & an ordered collection =f dake tach thot data & fasewred at one end and delebed Pom jn FIRST DUT (FI Fe) eng. Quene Pollows First another order 2 quenes ia Tire are Aitferenk Hypa] queue: “) Lineag. queue ( ordsnary queue Cafeterias, pebol takions a) Clreular queue 3) Doutle ended gureue &) Priori ly queue io queuu Can be Yepreeubed Laing aie and — kinked hints &imilav to Agneke () Linear guewe Tn” Uinear ae He dobn Pele L' : mt w added at one end Called year ond and dleleted at the other end called Frnk ends Ee queue Delebien eve] 22] 0 Tho [] 1] é a : Zi wre << Trsertion ; | tet Rear Quewe pperations: ) Inser- —)_ Delebe a Display @ Gasert 2 The addehen of new elemeuk to the guene. ia Called Yasertion and every time before — Prsertin. a new ikem rea & incremented siryt then j in tagerbed. ikem The condthon +o be checked fr fnsevbien i4 queve overflow, whore reas reaches marimurm &ige - Algrrilhm + “ Void Fnterk C) i if (rear == Max-!) 2 panlt (* quene. overdlon"); i Yeas = Yea +1; return 3 y[veas) = item; } to faces k Io, 20, 30, into... Gutene + a nen ooo GEEET + feb ces ae, % ihre fp. taser seas : Inserk 10 (irae b) Inmet 20 7 element PréRrifeut Feb fel feel T_T] f=o Fro Y=1 sO ¢) Insert 30 a) Insert Fo e) Ener So }10 2o| 30 | . [io[ 2°] 20 ao] | v3, Feo yer ° f) 3? He want +o fagevt- one. wyere oleeuk , Lay bo ey 10 | 20]z0] 40] 5 Gt Yeacheg to queue oVerdlow t + Ginte Yea 22 max-l yemoval of fyent — ebemeuk bem He Called deletion and athe. dlebeling He eboupeut_. He need to Facventeuk= the Frei poinkeg Te: Cmeibon to bo checked fa doltten & ze no ikerne ave prevent in the queue’ i queue under 4loe queue Vbid delebe c ) 4 af ( trent > rea) \} freak2= -1)) 2. pantf (0 quene empty’); vetun 5 ae 7 Paolt Cr yar LE y4 al krmt]); Sritially gee TePa5 Tae Fro Rea a) deleke io b) delebe 20 ©) delete 30 CBs Co) fia Fe Ro2 Re Fs3 want fo do delete, ik gi vey agesn ie Ne queue underflow, inte | F hat betome more shan eae all the obements fuom fom Desplg: Painbing fo ree & done here. @ onthm 3 desplay O t 4 Penk » rea) |! (frent 2--D) pont? (4 queue emphy’); alte . 1 pal te Brn; ix= ens t+) pak f [" ya" of); } ante. Year reaches max, Thongh quene hae Xpate T pis advantage: : See Ne Can't fasted nero denon. Pusu 2 ttreular qaete aa queue, all locations are freaked at Circular location Gi) follows the Lact _ én which ceduch that dhe Fivat- location gq [man] - Tee pictorial egiam of Creulay quese ts ieee void tndert C.) 1 #( counke= tax) Point (4 Que overflow’); “ee. £ ve (r+ Dy Hor BinEB* abe beqert’ ); - Acand (yd, debe); gly) = ele 4 Count + x} y Void delete c) t 1 (Counk = =) i Ponkd (° Duce cuneletlois}e ); ie : i pant (* deleted item is Yd) gf 47); 4. Gap ty Void Ainplay C) i if ( cowe} =~ 0) print (" Dersue unrdectle o\a ); dye, i | da Cet, fe dumb 3 tes count; ity i paatt (“fa a 4 Ex)); ake (KA) Y, Max 5 J Double Ended Queues (Deque) + Prmmounted a£ Deck Sin this Hype of MEE “Ensen tien ane deletion. Can happen ak both the ends. There are two tyres 4 Deletion <— TI Ss Enkerhon ers Saser key IS Delehin (1) Papa Restsbed Dequeree> da “this type tnserhen happens at only ene end and — delehton heppene at both he ends. zo] 30 |e] <— 3, ton ama cit Tape P25 @) gulp Rededcked Deyue? Ea thi tyre queue tngerkion —hagpene at both the ends ond — delelion i: ak on oud happens © my ea coll <~ Insertion Goser hO & galebon Applacakions: Tn Atathe Hae eae He hte Dew © Bieri, Queue + prtethy Due 4 dale Anche rolich Follows pire Wk ua foievily alaajenta ave moved to hart. ; Let ue take He § belo Lat 9 nae bp be placed in the gquere wilh pricte given below. Now potor? to htehest 0) 20 2 30 a ho 4 CAveat) a to pro Aine to is the | Pivee niumber tn the: dink, inde TEs (ii) tnterk go, Aine thet Go hag Power priority tan 10, fngeye 30 Next to © be To faey LI Gry totet Be, Kine fo has Merve prtorily then. Bo: Move .30 +0 the nexk lecabieg and, fazert* 2o bebsre 30, jo | 20 | 30 ] By tagert 40,.. Hint | 4 has eae Precedence ple ib afhs go [isa Tse] 40] : G) Dn cpu Mell eeting, all Joba are Acheduled a FIFO (a) When muh ple. vsers daub to. arcets Prinbes ave pub fa grseese- thovertol queues then all the veqperbs ) Sn Bread Fete earch are weed. Acker’ hector “CL, egainfeny | @ oe dunetien ie Yerursien- a clawie example to hes To prove that Certain tune Hons are hon Pomilive veeurdive fe which Can not be eemputed ody wt Laops Ne have eae becuye Pero nGiloms » Yapidl,, The anchon i given below wer Bpdly Ack (ot om, ink ny ae “fC m=: o> Yetusn n+l s tC rfz=0) Yotuin C Ack C m-1, »; velon (Ack( m-1, AckCm, rd); } : eq: ipome2 aid neQ — cae Alz2) = 4: Aa@ ae Ate) a! Be ACag)) < Alo, AC, »), o/ ie n= a 1 yy oN A(o,a(yd)) ay 02 Alo, A We L ee | aN Alo, alia) aoe y Alo, Aly” Teal y A (011) [ofr Pee : Alo, A i WO) oa Ls alo, 1} : 4 fo, al re St hee) Be gm ARC & Ack(3,1) y A[ZA (3.0) od ears A (20 als) DAN (\ - (2% 0) A(t, 4 (20) aly nls) 7 SS ( i u ui" roe a. me aly ats) db L — i 7% Ale als), Co aly ed pal @rly ala) |< Ju 7 A® ~\ (9) a) Alo, By we (0, (10) abu OD @ ALi, Ale), ° a Jf© b . ‘\ Alys) sng), A lo/1) vies @ PL AN Ay Cawe - Toned) /] F Ay (ses -[ave))] 64 (fe89 - [ave |r Av -vecave)] F A+ [ /- %8capeF) ' +A/-~* BCADEF- : “Agesthon J. Coaechng gn Saks Lepeurion Je posh Dopabs Sntix exprecsion dulpuk prefix . Expression : Methed i) Read Snfix expression turn right +o lett 3 if wreak Ager vel “3 sperand then ple tbh te probix array: 2) if current Agmbol a petals then a) tf Cuvrenb Kqinbel 9) then purh- it -o tteek 5) if wrreak iymbol oC, while C Mack E407] J = ‘9D dlp om BO AO ag Dif eumreut dqnbol i astthmalic operat, then os C precedente ( shack Ayrobol ) se precedence ( cum ext eyrntely PR aback Hop Agel] 8 plae ob in prey . posh the current “pnb to Mau, P20 A) Repeds dteps 2 & 3 unbil He hak grote) q : © inty 5) Pep all dymbé fem the ond place ‘br poks en presis | - 8) Paak- prefix, Cxpreston in reverse orclen. converts atlow Ee axlb¥o) - de es : ‘ Sntix expremon fo prefix enpreavion. Seal epote [ Pete Cees e e / a ée i. / ed ee ed/ 2 -) ed/ c ao ed/c *% 9K ede b —) * ed/ch ton = ed/cb* * -# ed] chy ~ & -% ed] cb¥ a, Nib nk ed | ch¥ axe Reverse 9 obkamed caprendon 64 the. prediy pref enprention [=¥4¥ be] de] 7 al Nu Deeprka, SoA Modul - 3 cee See i O Linked leks + Dynamic Memory allocaion Yevisibed — malloc Calloc, realloc, tree, tntreduetion to linked let, represen tation of linked List In memorg, Primitive operations en Linked tts, Searching a Linked “List, Cireular, double, header LL Applicators of linked Lets + Téephus problem, addition ef bo tong inbegert addition of two Pelromials, Linked represen, taken of Meals and quence. Tn linked lata Ne have +o use fynomic memory allocken -lunchen, Such of matlec, Callec, yealloc and de-allocahen —-funckeon Free ty. All dynamic nemo allocation -funchows allecabes 4 block of meron dumm 7 (ry heap blocks Nokes Pa. serbon and example check Perse Unik nokes Linked list ¢ Linked Uwe & a dynamic data Shucture which Crnivts of non ~ dequental Collection of dak itenys te Call linked Ue as linent dakn Arete because of the appearence af ibe be linked lee cs collection of iboms where each item Cmbnins data and a poraker (ord link of Nenk ibem- a Qoo 300 400 T | +— + — x [1+ a 4 thera 3 ey them 4 ct data link +o nent bem He hae Jug sduolnges of Woked Nats s 1. Linked las are dynamic be they Can gree oY) Shrink during execuben of dhe Progiam. é Memory & nok Pre-alloceted — fn Linked fe hence. ik enlomaget efficient usage “2 ee and deletion Can be ete O a Linked levts @ ait 3 Insertion ever in 4. Hany — Corn ple licah plex opp tations Can be eas dene Ua inked Mes. “i : "a Disadvantages cof Linked Looks # ) emus More wemay , becanre eve: node additional pote Eer tp derre the addres of nek node 2) Bearching a parhoslar them Hinge Comteanting. Yeq wives saps of Linked Late: » Single Linked Lite 2) Double 0 " a) Urabe 4) Header =" es Q Single Uoked live a A Aingle linked Wat G0 Wnked lie Collecken of nodes, where each node has ee pools fo ik ) da ee hich & Ling Co hdl, addres of aicnsder The Live nod & addres ts wereld in a — poenk Variable called. “Head! and th ' ae ae 2 Leve nodes — pla has Picloially a — in le linked leat below, 4 tat Yopreceuked ag Pa @ Head 500 Ea 1000 a 3020 “(2 v200 ]20 | 2220 30] 3000} || 40 a 4, dle pla, node node node y node! Representation af gp nede ia inked Uke t The nedes im Unked links are Yepresenked 4 Zell referential shructu res Gold veferential thructuee. + A Abrucure ts collection of heberogeneous data in hp Nhereag elf vederential Abructure sa. saiclure whieh hae atleade me freld ohech a pointer to ibaelf- is A node in leniced Levee Yepreseated 24, BT oe [geet Ae Fidaln @ xe (A | int data; Alak. ¥phy; ae ap @ os ‘rack : (A) Fnexk com be uted. 7 Fo declare * Ogbart Ne should give 4, (gid Alar ee 3 To declare Aba at are pointer ty Pe, Ne give [seek 4 Alot thot typedet: tpedel & 8 Keyword, which make q Variable a date type - ey, if He que Aypecel Moet slink node the normal Variable ede hat become a dakx-+type called Houck Mid, So to declare a pointer Variable Merle, Ne Can je Mak :| trgtend of allows ue to Prinihive operations en Single Hoke] Nee Crealion fee ak beginaca (2) Ensertien < th middle Cee afler a given node) ak ending (8) Deleon ———~ at beginning. in middle t dew i: al ending to Crecke a node, He vill txke anebien (1) Lrealion + Jn allecke memory fo node mallee t) + hamed newt, Ne Efe ne 2 lnode®) malloc Caigerh Coded) 5 Void Creabel) ; fen ee New) s fiode*) malloc. (Aige of Crede)) « Prin (en be abe |x "), Beant (4 fie Bess data), Nagi ptr= NULL; “Head = news! ¢ i Through treske funchon, Ne are treaking only ome node, be the tira node fa the (lw. The Yemain, ng nodg We will Create theo neh Pager on fanchen . © ieseeen Snacking a rode tate Lik cs postible, tn ree potting Sn beginning, Tn middle and ak ending. Toserlin ab begtoning ? Head Pr jt - Soo af [09] new! Void settee oO : new! = (node*) malloc (Mgeof (no de) ; pe(* enter new node\n" ); aft yd" Sneoi—> ata) ; Newi—> pre Head 2 Head = new] + } Head 200 a t 300 Word fnsert - end C) Neal i newl= (aode *) mallocl déxeof (node)) ; ps (« enter ew node dala\n"): apo fd" 4 newi— dala), neol—> phy = nul; Prev- dead ; hil ( prev > plr |» NuLe) Preve Prev—> Phy; Prev—> ph& = Nevsl I Zesetin Aer a given clement Head loo oe Del : aD kegeas pik Tnserk ab - middlec) on I Prev= Head 5 New = Cnode*) malloc (ize af (nodey), Peek} ( enter Key and new node dal» \n"). send" Ld di hey, 4 newl—> dala), ~ while ( Prev data |= > key) Prev - Prev—s phy, news|—> pty 2 Prev —s phy, } Prevo pha = Newol Delekon + Deleting a node trem the ingle linked Lik th powtble ab sthree piling , debing oe node Daye node, ang given node . Pr geletiag the Lost ode + @ tad ub at 200 (ies jo be debbed Void del_ ak. bes 0 i Stree - Head ; Head = draak— nexk ; Pree l strate), y Belling Me dae node + Head. a loo “300 : ]te [20] >] elie x prey fai Void del ak- end ty : bos = Head + whib ( Arab —> pha. b= Nutt) 5 Prey = “ate; Kerile = Hear — > phy; t prev—s> pba = NULL ; free ( oak): Pe Delhg he grin nel fet ° 900 i soot ie =i Sis — fio] na debed Void del - ab- middle) i Atvotls = Head » ptt (Seube, dhe node to be delebed|n’); Acanf [" Jd" & key), while ( raul» daka Le key) Preve Atak; Hoty = share —s nexks f Prev—> ptr = saat > phy . bree ( stat); } vsplay: Al) the Linleed — leat Dispos cles ents are. A aplaged due rest node to Aa node. Vid dveplay 0 i Slat Head ; whib ( dale > pl d= Nuit) printf (* fd" Atak dal-n); Neos = Abagk—> phe, y punt? (* fd" shut—> data); pisadvardage st Sele Linke) We @ «Me tent ateem any ikem divect ly. previoug blemenkas have. » Cant occens the once = We ferwarded the — pornkex - Serrching 9 Linked Lint: + element fa the Ring le be wed cP be wank +o dearth an linked Ue the deloo wyethod — Can Head cn be on ee 400 [io [eo] —> [a0 [300} > [20] 40> Tae Md deb WB hay Ne wank to deh Go lich pur kes, Woid earch L) i Pantd (“ enter tlenevt Yo be Learched)n’) Aunt" 74" ake); : Shub = Head; pe Work Je NuLL) : if (toate > deta 2 key) Yoturn ee 4 Meas = wale —> pba; 5 Jj Yeh ‘oy i ei lip =» chek fab peqam : Kage Unked Reversing & t ard double [inked Use —> Arnignmrens U © Differen hake ‘ing é 0 G9 Double linked — Utate = (psy eee eee eee pi ts a collection of nodes, where each node has three parks, Pointer 4» He previout element, data, and pointer Jo nent element a the live. Head hodel dea > [ie 190 Sane i ae st node y bet Leki alse 2/2 k—|eo[ftet —)aeo[ ae BC] pre BM next Through pin, Ale Gan traverse fo wisit The Lise of elements in both the dereetions - (1) Creake (a) Poser (3) Deleke wy Display Creake Here be Creabe ov Pulte deaf Create she tucture, ; : Nokes Howl — dliat Fimbeod 4 Yprev 1 and tnenir, Ne int dake ; can we Abr dod, Youtk dline ¥ Prev; ¥rpba. ayoutt dle Freak; % typedet Abeuck dat node ; 3b on Void Createc) 4 newl = (node¥) malloc ( 4éxe0f (node) Pont PC" enter the into\n"), sean (4 fd" 4 newl > data); Neve] —> Prev= NDEL, new! > nedk= Nort) Head = newt; Head. 100 1 Tnsertion ¢ dnyerh gato Double = Ainked Live porwible ab dhvee paifiens: AL begining, ak ending , and in the rpc position Snsertion ot beainrng ¢ loo 200 be LoOS 10 | 20 [Ivo [20 | | Void inset SCE] F i new! = (node *) matlre (Hz04 Cnodey) ; prin lf (" enkex data\n' ); dean (* JQ” > &newi—> data); New) —> prev = NvLL, newl— next = Head; Shak = Head ; Skagk —> preve newl Hud = heal ; P12 Insertion ab Enda hi Head Void Tneert- end C) ee ae i > Sole — ol neal = Cnode*) malloc (4iz04 Code); fee J 300 Prk t( onbs eleyent|s"); ob LX deont(* ya" & newl—s dak); TEE Newl— nenk= NULL y Staak = Head | whil ( Mratk—» nenk p= Aven) gong fo Aese Hole « abort 2 Neth node New| —> prev= thas ; Aotk > nenk = newl, f Frecxhion ob fhe weguired fotilion 2 Sn thea Ale Yead the elegeuh after which we wank de and dos indertien' vil] Paseok Head Voit taser - middle 0) : newl= (node*) mallec (4x24 (node); Pant? (enter the data\e"), seant(* Yd" Anewi> data), Proll [* ener Re element after salve you sent do trsert\n" |, Aad (" pa" a key); Shot = Head ; while ( ghak > dale de eew) gba = Skat > newts newl—> pev= dtast ; newt —> netk = Arash nenk glare > nent = newly nuwl D nenk > Pev= Mewl; { Delefen 2 Deletion in DLL th Poible in & poviling .) Deleting the rat node +) delet be node. 3) deleling any qiven node - Deleting the First: node + Head, oN jf Vid del. ak - bey d i Goo oo (ebb hed ca Stag = Head ; Head = Shas —> nent Slart —> neat —> prev = NULL ; 4 Free ( ght); Deleking the Lee node 2 a eet \ord -del- al- End) tee 1 800 = 300 5 awh He fm = Head: pre while ( 4. —> pment Je NubL) frees Cur} lars Wr nex ; pre —> neat = NULL: hres ( eur) I Delekeg ong qiven node 2 Head loo EW Be 00] 40} Gal pre Cor 0 oo eo Me [ok] z era 304 bX] void - del- ab- reg () i cur= head , : print? (* enter the ge be be deleted \o’); sunt( fd" & key) wolilr ( cur datn d= keg) i fee = Cay: care Cura net P15 3 tuy— > nenk ; ee Pre —> nexk = Wy—> nexb—> Prev = I fel cnr), Displayrng the Lie of Clements. Despley O O: 1 if ates ly ss | Tah to Ll digplay ¢ replay 0) Vol day i i ars head Ww ile (tery Newt g NM Stas: Head » Core. sea nents ie whi Hee Whib( curs pry Je joy CO tease —o nent 42 MeL) Lee e7 at ay shan Zs Cure curs prey, Piatt (* dcr’ atest ea) Stave = Shast—> newb, L 5 Print [" Yat stask_» dabn). D Ciel, leoked Lies te 5 the Late node & pointed back +o the linked. lites if & Fn an divide node Tk Can be then it called — civeulae Unked — Lee. in two pau, ) Crreubay Lingle Unleed te Dd Crealaz double lence? Lee Advankage: Any node Can be atcemed deem any and Lay ee. aa He Fiat node Nede.- P16 GB Lireuler Single linked bade oo hruck lige et cll : Jo | 00 feeling ae] 30 iH int = dala; Moutl cleat * ply t type det Youk cline node ; node *head, * drort, F pre, F eur cc EE es Ae Void ereabe C) i head = Nie; print? (ener how mana nodes \n'), sont (' vg" ga); Lil t20; Pens ta) shad: = (node*) ng (nodes) . Pan E?(" enter datn\n"); Berd (Ld & Sort —» dabn 3 Bose PhA:s NL 4 Chead 22 nui) : head = Haak, tode Creation —_ —_— vid cret) ‘ ig (head == NOLL) Bade Crodet) malic Cpl) 5s Cools) dee Lo ples heady cur = head + whthe (prd—> pha. de mute! (Preaphr ; Pre= pre pla, g heal) Pre—> pla. = Atask Me os > pha = heads BEoater data’); ail" ta" Sehead-> data, j head—> ple = NULLS a [Leb alee Creabed 8 Single Circulay linked Lint: sue, 3 potions a) ab beginning b) ab cading c) al ang fake. Vo'd tnaerk 0) 3 Traeds 2 Trevi fa sy peable at fak och; pant ("| be a End 3. at-req|n’} Paotf (* enter choice \n"); cant (* Yd" &ch); Newl= (node*) malloc Cre of (node)); Pak l ( oubes daka\s |; Stan$(s yg" & Awl > datz), Ano? leh (ch) hack 5 . : ok? . [00 200 - begs Ae a eee eop—> . Abe 130 ple deh ! nevol > Pbr- head, Sslet while ( Aras —> ply }= head) Yeouk = Mra > pha; Mott > plas newl; head = newt; break; Abe ewel Case 24 both = head ; —— while ( Yak — pha Je head) head Wak = Mork — pes. feoFy as 2 joo. vent 300 Fee > do Bah ->]s0 100, Pre New! > pha = heads Mook» phr = newts break » Cae 3? CH 100 200 aoe pe I>] 20 | 20] sch 2 fed ADL require Poo tien teak = heads, ‘ [40] 3ee ' paint t (* eater key |r \; neve] scant (" 74" skey); wile ( Apne 3s deka be key) Virus = teruls > Per; New| —> plas thaw > pha: Vrut > pha = Neral ; break» Q } Dele hen Debian a node liye (& PeMabe ab 3 pashions a) Deleting five node b) Deteting dae necle fn Civeular Anal Uraleed ) Detihing the veyed ode Void delete - tir C) | vege] Pink P (4 1. Abe beg og At-end 3 Ab ve \el, pant (* enter choiee\ a"; Acanf(* yd" Ach); Avwtheh( ch) head ; Cue 1: ine loo doo 300 7 4 ; ; , 10] 200 Fy” [20/329 EL el, a Pre = head ; Se Stayt - head» ee deal whi Atma > pb J» head) Mok = Henk —> pha y head 2 Pre > pea, Urast— pla head » Free ( pre) ; breale 3 J Peeend: Can a: “(ery He eaer Mp At equa 4, a Sys ia) wohl (dak dpa ys (Aauge Logic ¢ odpla J. Keydy p Prez ease can be felleeed) F j You = Mol —> pha; Pre—> plr = task pla; free ( Heour); break ; [Alege piles «el Rt Coe 3: ‘L, C node ~pre> NULL: Star = head ; wlll gosh > data y= key) i Pre= stot Seok = Aber > phy; iy(pre == NoLL) then head = Mead — ples Wd, prea pkr = tha ply; hee ( stot); break; I Display: Ne Can Ware reiiitasitt Least a itidals ttipoy nh @) ni tw kf. | Traversing firm Left do ight + Void dvaplay) i Mosk = head : while (tal > fs Je head) ? MOS b>" dttads > data); both = dnt —>plr ; j Pil a", dewt > darn; p21 Lirealar double Linked bot @) An 5, double Linked lat Ne have two ond ale though prey —> which ts Lift pointer. and newt —» which oeghh poinker. xl Th Cireular double linked Levt, Peat nodes prey Orabaing the adden ef Lue role and Lee nodet nett entering the addrer af diva neder Patmi Hive operations are, (9 creabion @ Fnsertion (Dele ion ® display. reabe © Sn Crealien, Ale Can Create only the frst node and all the verosnig nodes Can be Create though Pasertion (0 he Can Create ‘8 number of nodes the begnateg steel. ereaking SM one nefabos 2 ole Void treabe () i Ponk-f {« enter dals|a") ; auand (* fd? Andy > data tp )s newi= (node *) willoc ( Hage H) Crede)) 22 newt -D phy = noel + eel > rpbS= Kewl; 4 Sryertion at ce all tloid in-begt) loo fecceree 109) [ 22] pia ma i cus he LS [2 foo a0} New! ad; nel: (nodet) malloc C4ixest (node); 02 (euber dakala’; a(t ya) Snel — data); new|—> Apla = Cup stphr; New} > rpta = ty whil C eur—s rpbs. |= head) Us Cuore, Cus rb = net; head =newl Inger bon aoe See fh che Trtark- abe reac 0 @® t ture head ; Mew!= [(noce*) malloc (tine 4 {no de), Pank$ (enter dan’); Sant" 4a" gnesi > dala), Newl—> phe : heady S tohile ( cur > opts J head) tw Caro ope; new)» Dpka = eur, Cut» pbs. = neol; head —> dpba= new! , Wisdex I driervbon ab the double Ainleed — leat Delehoy + required po Hon es Aame ag yequired — Polition. Fatertim ab Deleheg eect dirculr double Waleed bint ge 300 100 [e[ sek —=]2 [so] ofp Moid del ab beg C) i eur < head; : cae be —> Upka = Use Lptr; aun Siete —> wpa = an rp; head = Corsvple, } Pree ( coal dhe Late node 2 Void delabe- Leste 6) —Foo. [feo] 2320} Ck = head : aye = Crs —> Lebar: dost —> Lpir—> rps. = dave» rptn, Cut —> 2pbr = Lor > Lpta $ free (dase; Deleting dhe reqpore node & Layo a4 debbing regpired pode 19 Couble Unked Links Displaging the diate Pern Arfk to ght 3 Word. dentes- deem -LRC) cuts head 5 wolik ( cur —> > : pits ya® Cups CUS apts; Hr pe head) ou dare); t nt pa ou bees); 1 Patery athe __ lite ben wight to Lik: splay - tiem am = nahh ZAC) 8 i head 5 i Cg = UD Apts; pe(t fas ow data); 5 Frobsh [ow Jo hed), @ Header linked — Leate ¢ (8) Header inked Lt %& one myore type op Linked — Leal - tn this type, Ne Have & dpercal node — presenl ab the tho Luakted lest» This kpeial node ts Wed, beginning of tnfermation about the Linked Lint; tp shere 40me wtebul Aueh og number of node present or pein fly © Grown pL ia nie node and 40 7) y Urealag WEL Lave nodes pry ¢s _lo0 toinking be tie [helt Joo Header tole 200 300 0 [bet- lo [300 |} > Qo 4204 30 coder Kelked Lents abso Cobain the like forex fien ab hen Co Advan es As header rode, the eperahont delelon at fume will never rcey Crealret) header = (node¥) malloc (+ige (node)) » head = heada, ghasb= header; Print (* how mang nodes to creabe |n"); Aen} [* Ya, an); BR [te 04 ten, i+) ; - (node*) malloc (xize j (nede)); Nevo] = Stas > pha = nel, prinkt (“ euber data of neet\n"), dont (" y.d) Anewi—s data); j j nes]—> pias Nut; sash = nest; displaw Oy i Meost= head pls. ; while ( Moub—> pa J que) PRIX Ld! atetk dale); 4 Wok = Abas —sphs; pf f" ‘Ld Arak > pr; } spetahons Atke dD tagerhion ee to, ther lined — Links ily seni bad Can be pevterwed “i amt. Lg = tntertien and deledim ak of the heador node. ge Alfred eh, : he 190 20 (S00, insu - beso) L tia iba ; newl= {node¥) ae an (node)); a [teuter dabe\s y ag (echay Smeal > data); pbddise WEG new! —> Pb = headee > plas 1 headed. = newly 7 eee eS dilute - best) singh. headens> PPh; i headee —> pes = Adask prey perl Meaub), \ © Applicabicas op Linked Lent 's @ (1) Josephus problem (a) Addition of tee de tegen > Addthion of tee pyromial (ay Steeles ving Leelee Cat (5) Duenes wing Unked Leak @ teers problems one of the application — of Circailat. Lined Lats os pote hus pooblem- Josephus po>lLem ae abouk a pooblen, wlure there are on people Handing ta a Urle to 8 pyoubed. The. coring heen fam ron ferten in ihally aud mover op & Cerdein namber of pele Person & killed? ae e-uenebiern pevsen an He dame tare vepeabe unkil only wm pevten 4, who 4 aid fo be the winner. ta choelusise divethen +» In tach are skepped and the nent in emntinuee fue the nent yomat ge comider Ne hove one & people and te. number ApS = O° d46) tas ™ a (1 hep fo) stP © 8 Oo ys. Lod ) “3 piled co 5 je BOL tinal fe ti) peat tiled ty Go Ged 5 walled P28 gS llled fg (!) mplespoubsbien iat qeephus ( node head, fol 1K) k: ne q dupes 4 node pe, FON, vob 4y - , cuYe head 5 while Cour > next § = Ga) 4 tal eso, tek-1 5 T+) i re be, Quer = Wyt> nexk 5 Pre —> nexk 2Cuv-anexk » painti(* yg cs killed \o") Cx num), Free (Oy Gag = pre —onexk 5 } Peduwn tix net) ¢ m0 ises{uzstuaaisazeisontcaagibay (| bee Bo ) Ly iy ish blel= led Abips =2 ’ hi fistie- tial Be Bs “il rp Vr + b tilled Kp me ew ie Etat 3 ann, tele fae PLA 1 dele ee 5 killed yoo go Z % | >] #[20} ° Ste = a & lullef 5) aca ia ise N PAX? eg os Iealled yo os Kelle} » Lidar 2 , fi (~ execabed . eee rey Niane 8) fale] a0. qaephas pro blame picket) Popresentectiog wag Kenked Lage. @ Addttion af choo Leng tod os Addthen af tee infeqeré tt Ths & Cahiem of Lalled Wats. ae wig double nee Ine) ape Ajexthm: ; 7 ib fo taken, ) Read trate dng inbeger at Aeitg Conve and atere ae eath inbeger. wa one node 4 linked - Liat. Vv to. 40 ‘o 20 Bo |__>] Se eo) bok] hale E272 yo k= [aly ok fide oy Read aw inbeg alyo in fame manne - SER : ilo Eas BN 3 add the daye node op Lint] and Lode acde Ff Janta, sere fo The ther lide + 4feve Camp in Seperate foriable, repel” saps vith all Hee rematnteg nodes 4) Finally pank te vesall . st 5o0 boo joo goo a lake elite lel Too] >< 42345 4 678 = [3023 os = Progiann: Void add ( node * head, pode ¥head2) i Sak p dur, Vem, Caso j node 51, ¥52, Fnesl gle headl —> Tphry 822 heada > vphy yobile ( S1—> rphr Se Noe) Sle $] phy wlole (523 mph NUH) $2 = Saar phy y headerd= Cnode*) malloc C&ize of (no de)) ; headevg—> 2ptr= headers > rplr = NULLS preva header sy whik( si Jo head! S& $2 $= headed i ume Sid dakat 29 datat CA; newt: Cnode*) malloc (-Aige.o} (node); pev> vplrs neroly newl > dala = 40m yf. los new| > Lphr = prev y new|> vptr = Nebky Prove heels Caz dam | 10; Sle sia epky gaz sa Eph; } if (siczhendi ga sa Je heat) newl= add_ leflovesList ( $2, nel, prev, Sum, ay ole new) - add leftover ex C $1, neel, prey, dum, Ca), while (new! |= head 8) i pet fal, Meni —> date; ; newl= ness] —> Lhe; 5 Noles lube g-leflover i dak bene ey rode add-lettoverlitt Cnode® g> node nest ade prev, ink ue 4 fam: gtodata+ bas how}: (node®) enaller (4igeof (node))s prev—y wple= nevly newl—> dakx= hump loy Reol-> Lphre preys } newl>yples NULL § Prev= Nev > S- So dphy retin (eres) 5 ‘7 ca= dum |i;

You might also like