0% found this document useful (0 votes)
14 views16 pages

LL 04

linked list

Uploaded by

anmolbansal1969
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
0% found this document useful (0 votes)
14 views16 pages

LL 04

linked list

Uploaded by

anmolbansal1969
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
You are on page 1/ 16
Pow = | es bhi Roi ques ko map se Solve kx she Tonge: Coe Should have am alkanative | Appseach fox that queHon even if that “Mond |solwsi on -takes a er a -jfemetesitg than _map solution e 06 ML 1023 _ = es =i a a =i ss A)| Set Fart amd slow pointers at heal, )| Fast 52 sit bs slow > Isp _@)| TE loop is present | pomters _ eee at: GQ node Tha . cohich ells that Linked List has cycle hen both slow amd fast pointex: S embens » & Fart pointers ak one node, they, _ Slow ‘and Foust poiniens As een — eventual cand at ont point, coll) must meet if hone iso “Joop in Lbs clase solutign { “ WaaCycle: Clistntode™ head) ¢ lattiode* slow = heads ee Watnode*. fost = heads cohile Cfast |= NUW)E fast = foot >nexts Hern a, 4 45 Given the head of od rede Linked Uist _, stetusn 4 Sn _|mode__cshente re _ cycle begins ae _stoating—— ipoint dk the loop» He tates —me—eydley ARADO | | FEV A Tr her paint whew, Ty | SebudedeEaITITOLS a _ a — _ i = : a : | => _ = ant 3 al —P tas) : 2 a 2 fort Slow _ | 2 os i sve - SP [ As, distomce travelled ‘by feat pointer, = = LX Adbtamu travelled by. slow pointer A+ some cycles + g =UA+ Some other cycles +8 Neyer see ares Ss Distance toavelled buy fart after the obowe positions of fart amd “slow — = Some cydu + © - @ xo 4C~ @” ; Gere - 8 = Ke-8 —@® Fot0m eqns ® > Ate = KC 7 A =kc-8 ule [fost kom uhi__stkhne ps gb done ko 1-4 __| dono__pointexs Starting. poi imt_af he loo Pp | Thet's s_coky, Siow. “ko head por | gome . Se ond px Siep Se move kowate hai until (fast |= slow) px met kan gate hai. Font = fart, 2 if (fast Le NULde i aa Fast = fast next 5 : Slow = slbwonert; Ff (Fat= slow) h boeak; ee = if Chost= = NULL) Eg { . MUO SIRI | vty Hie setwun NULLS Slow= heads: chile fast | = slow) £ Fost = fast phext; Slow = Slow > next; netunn fo ks, X | Remove lo [Remove loop in Ninked= Uber ANARRR AKERS _supie| Find stasttig “point of the loop. -* Step 2-| Make a temp - pointes Hat’ stassts Succ = __|staseting point of: Qoop med ea until“ dtnp next equals Stanting polm aaa ws! temp >next = Nut. 4 « = efienp emp ———& & —__—_——® C= e temp = ee — & & = f [ree pe NUE ee TE mented | ——~siew= slow > next, = —_ | he et—™——CE ~ | 4 (fast saslou) SA on 7 © bxeaeg : TT caite’ Cremip next be sto [Node * tasting Point = Tasks ___|_ Node * terny p= _stosuti ing Por nts ump nex 2 Redes LL kee srevorse Wrne ki nerd isliye pai coz. [2 obsexvosions > * if (casny==0) , in that case break ‘Roe Jao. “2 Te Ceamy [=0) amd last node px deme stand kaw aha h, th Thot case New node create bani ow wme ko Quah. ioe hai. = divers night to left hota hai bub LL _mai stant do LeFt Jorma postible whi hai-Thots why sevecse [to Let anno. _po! ; SURV OHS bake fin add kiya. ees 2 Re FLL Ri Nast node ko « lpdego yuki chomces hai aca khim ho 7 alg se proce krna ha not equal 0 w Sov neu node Ye temp Shext}=rnull ABA ARO we ULSINg— @——-@ —@) = * Hotalsum=\o —_tetalSum=to"' totalSum=to lAigit=torfto=o digit =lo4e1e=0 Aigit=lodele= 0 He i = lo] lo= teflon: Cosny= tofto= | Cawuyslo}io=| Cover, tof to fempodara=digit Aemprdatacdigit, temp? daka= digit - He wala_Raan® while loop ne kiya |S nede ke alg pases kiya S| 7 eee SO) SE) 3x Gory 10) ‘ . tha, Wat's cohy am new node add pa PRATRRARAAA hiya on Usme = caro, pun ba, 2 diya. = f e-= GGsseeeeeHeeE __ Node x “nextNode = cuser pnext | Cute next poevs ae i Prevs curs ee »—_—— as mextNode + = »—_—__ ‘ i git - , Hekusen prev j = - : > Noid addOne CNode* head f = ; : ~ => Moreverse one ie - lL head= stevenselt Chead); ie —— = ee = M odd one EEE > | Node * temp = heads. a - int ot =\5 a cobile C4emp >rext b= NULLS ! | SWS GIG int digit = +otalSum Yo Lo. tay atten tag semp > data = digits temp = “temp next: 1€ (cosvuy =. =0) et, |_____,_bueak; VVBVBVVSS int _totalSum= emp >data: “teas | Ml psocensings fo a | if Cem Jeo)fo Ant_tvtalSum= temp deta teary 5 Link digit 's totalSum ofo lo; Cory = totalSum flo 5 : Jermp > data= digit 5 ie (carvuy § = ok: AA RAAAAA SS SEAS hi — ____ Node * newNode = new Node (covey); __ i _demp >hext = newNode;: " = : Pee telilealet Eee! ss =s 4 = a : =a head= sreverse Ll! Chead); 3 | pun Given the head of —o._linke, Medes of | the Dist Rok Hoe_mnodified tint Riso. _positive inte ox ons Pita en om equal the length of the Unked Ust. TF the sumer S_is_mok_o._mulliple of then left out — [nodes Wists ‘ene should simain oa» it is ee ———ples_mnaty, mot_adton, Hoe Vollues_in’_Aint'smn oc co jonly nodes _Hnemnsel\es -sonang be homage. | ____— | ae bP head= 0, 212,4,5,6,3,8) ao 26,5438) Pos= 0 Pos = |,Pos=2 (loop bueak) \ care hina SRshya — =e yao \ AAARAAAAAAAARARARAORS ee | exev head |. stecuxsion kaAins eee eg 7 head Dhext = sucunsionka Ae S35 — i aaa “netisin paev; ” e oe : fee eee es = ee = = — _—_— p ~_demp= tem temp = seats a = = = = S = nintode * * sevensekGnoup Cntttoae * puree NULL UsiNode * cuss. = hea * head, int ROL int lene _ if Clem next =' RecAnsy Heusen sn pe, es Higsewueiosey SecAns = deverse KG soup (netNode. ,k)- 5 Himes head IGivem Yne head of a sonted Linked: list , delete. - | cbt duplicates such theik” cach eluvnert _appraxs only once» Return the Linked Unt sopted ov» we AAAS AR AR AAS SSS inf aah it 2 MHP ends ChB) eel ee it th | wei tk neepnrere all = temponent ovat) P/ rece Et class solutionfg porlic: ea | Aistntode* deleseduplicotes oes head) = if Chead <= NuLr Al head Pnext = uy _ sresusn Weads Ustniode * temp = heads — cohile Comp b= NULLJE _ if Gemponext |=NUUL Ak temp. eos T : meme Snextoved) LVisitode *nextnode = demprnexks = Jempanext = nextNode > next 90) nextNode >next = NULL; _ delete nextNode; E a else jumps temp > next :

You might also like