DSA Assign 4
DSA Assign 4
.... . -- ,k __Objec.J;~,-q ~
-;- ___ l-
~ =---=~~ --
- -=~---;_____
r~ io--U-D..d ~~si(I_ () cL _-- __cj{£u} c,_ ( _ _J__i_o_k (J cJ Ls_L ---~--
---- - - -~-- --~_:_~~Un d e-ts_t.0~cl ____t"hf'..__ _.Q_ -
p: ,e~ ~< ::~LL._:.c_,· J~.1:. .,e,o__,,__'(_ __
---· --··-· ____L1.nkedJ.rst-~ snsed __ ~ .QJ:S!')lcJ
h ; DeleJ@ _
· - · - - · - - - -1i ----
- -- -- - - - -- -- - - - - ---- -
---- ~ ~{ ob k~ 81 rJ en}_f>.f.:°L~ ·. ..- __ _
- - •· ... ,., --~P,J_.T~pJP~ ,e .~__ __:c_i. ~!
-- - .- f.2.££lru-rri -.opeccJ, of).s ___ n Q..c1_ :_ Ii ?-k~d L~st a.o d
, 0 L _ _ _ _,_ _ _ _ __
- --~- fu dr omfl S : - _ro Y2Lf2 !e;/ ,'oO -o .~ ed ._ .1 _W j I/ : -
.. OJ ]_
_j - ---;'> . .c!L n - ~- e__:.Cl _,,-cu.Lclcilnked · L'i si . . . r
. -- ~ ~ .ih e opP<c.fici.=~-___I...L'LJ____J.. .....!..•~{i~ C,(
""-.!.--=-:.....LJ......C...._._..-.......,,~
-- -. .. .- -- -- ~ tl__d.d-a, L) 1s p1o.:) ib?)?J , ·.D *-'""'-"· ---.. \-'-- ""-- bA- "= <
¼ oe ·& · H~£C.tw.c>,e 1?,e1kdr e . ·. -
- = > - - ---11
· · ~
..__ __ _~.--L ,,Ll,,
.U.... µ.c.L J....U
. L_.I.L·.d..Dtu {CL~ opercJ ing ·Scpit>~~ ., . )
U.....- ':-_- _,,
·
' ~e JV-
4 e :~ V~.!kkop R ke\. b ~ .
.r ·
r,;;, ,- , , )
srz )
~•')r, f ,,
7
- -
- - • t lel_d f_ _c lo.s5.__: - - . - - -- - -
,,
-- _____E{?-f-of';3_e.D_fs_ ectd\ __§\_c)o}e -L~ i;he ,,.S~-1- w'Jjh_ cLcQ0._
- - ___ ~ yef' e<e(\_t_ e_ t;p ___ r'lE';;f r)od ~ ·
___ _ _ - - - - ---
- - - ~ LL(c_t.J_(\ _r l 'rnkeclL1s_i __c la s S'~ __ _ ___ _ - -
int dcdQ_~ _-_ _________ - -- ______ h__ _
- -- ---
--- --
- ~ 1nJ t'( f (
. l\c,, c\ ~ nPLR ) _ f t c9.d _e_ ~-~ _f'flel _d ( i - ±
"J cY•-- --- -
___ --- -~- Fst, 'f"\~,nt~_~J~ _ fhf: r,rt'c_u lctc _f _e_~ 1e_t
-_ _ _ eJeie ( ,rd acdc.J : -
_ _ -'> n__
- - - --- --- --~
------ r , .£~:c)\te a no de . ePictb dCL~Ci. _, a~J (is t ,·~ -
--9p ~Lfj 'c _ __
fv\e1_ 1o ~ ~ e _ _ _ C[1{'[ Ll.c~& 0N1 Lt '(P-_. __
- --
___ - pC) ~ ( S __:$0
r -~ 0 _ .
ts_pl~ C )' : ;- _ _ __ - - -: - - -
_ ____..I)' ~ -- a.Jl__6J c, c Ie5' i1J_--i t~ I i51;7 sbm c.:ru.1 £(/- --
th.e1' -( c,
a. ·,n C}
(Ou f~t6 Co D'.f\ £(:_ ,t~.
C\ 5 S :
- - - -- - - --
__ _
_
- - - -- -----
1
--- - - - - - - - - - - - - - - - - -- ------
__ _ ___ __ _ _ __ __ _ _ __ _ __
__ __ !~·__( oo clusio. o ·: -
. __ Y:ff __/ fJ cl( n _r/o__1rn.pJeow rd Ci crc..J et ( Li 0.kecl List .
_ __ _ _ _
l j i _~ '-=
c::-r-}c.Jic-n ·. ~ -/\-:
7<' ._,_ ~p /9~E~"~
.L LYJ-
/i·✓~,L~CL :~
--.J... r u_ ..._
k: f'Cf J-.!5 ~-
J'/ q. .-,.__ l
1
Q_ <0 at
.lc)u
'!lynolo,
I' 1, I I
- ✓
~P~ t Nn 5 ("J )
--+-
I
Date - I I
Page No: -
-:: :A == == = == = = = = = ~ = = = == = ==
==
\, 1\! c, cJ e_ Cu (xeni ,. . b.Pa cl ;
ii
11
i Jh { · ·· .I
!I
II
IIt m
j
I
(1,., . I I )
(, , ~,, r.: I J
I -
I
' '! ·,
-- - -
- . - -- .,
----;4-- -"---'----"----=----"&=' o_ _, dl-,sb : /() -'> 'LO -')c3C) -> /40 -'> Chp~d )
~P__,6lk~
' · ioi h:ecLJj;~ a.ft~-, cLJeiio": /~-) ,?.CJ--) L,c -) (~~e1J)
~ ('\ .!,.._
"'-'- ( __LJ'L.LJkrcl LisL a.f t~ di()q h cl: 0 0 - ) ~ c-,(1,~
~QI,
- - - ~~
J __ _ ___
__ __ _ __ __ ___ __ __ ___.
'
- - - - - - - - -- - - - -- -
- -- - - --
-·-- ·- - -
__._._ __ -- - - -- -- - - ·- --
--.- _/1 -- .
- -- - -- --
/1
/1
= == ;
1· ,u: mynot~ 11
:A, "n,. 1, 1a1tn II I
C
IJ J '"• n,ava /
J
c l a ss r1ode {
i nt da t a; )I void delete / i nt data
IJod e next ; 31
62 // Display t he list
63 void display () {
64 :. f ( head •• null )
65 Syste~,.out.println ( .. Li st i s empt y . ··) ; Output:
66 r et ur n;
57
68 J Wain.Java x
69 IJode cu rrent • head; J . .,.,
70 do { 78 public class Hain {
7I Syst em.out. pr i nt ( current.data + .. -> ··i ; 79 public static void oain (St ring [ l args
cu rrent a current. next; 90 list.delete (20 );
} while ( current ! • head ) ; 91 // Displa)" t he l ist agai n
Syst em. out. pr i nt ln (""( head )·· ) ; 92 System.out.pr"'int (" Circ ula r- Lirkeo L!s t aiter celct i or · " ;
IS g; li st.displ ay( ) ;
76 94 // Delete the heaa
;7 95
78 pu bl:c class Mai n { 96 list.delete ( 10) ;
79 publ i c stat i c voi d "1ain Str in g[) args ) { 97 // Di splay t oe li st again
Ci r cularlinkedl is1: li st • ne,,1 Ci r cularL i nkedList () ; 98 Syster.1 .out .print (''C i r-: d ar Li rk 1?0 Lis t afte r celeri1g l'l~cla
80
99 list. disp l ay( );
81 // I ns er·t e ly,'(e nts
100
82 list . ins r-t(10 ) ; lOL
&; list . se r t (l0 i ;
1 . insert (J 0 ) ; Ill C·\W,ndows\Syst•mll\cmd "'' D
es ist.insert ( 40 J;
·: \ Users \ADH!N\ Deskt op\My Programs >javac Hain. java
// Display the !:st
87 Syst eo.out.p rint ("" Ci r cu lar L'. nkeC L'. s t : "") ; : \Us ers \ADHW\Oeskto p\Hy Programs,j ava Mai n
8 list.di sp l ay() ; .i r cu!ar Linked List : 10 - > 20 -> 30 - > 40 • > (head )
I/ Delete an eleMent :ircular Li nked Li st af ter deleti on: 10 •> JO •> 40 •> (head )
!rc ula r Linked List after deleting head : 30 •> 40 •> (head )
list .aele t e ( 2flJ ;
I Display the li st aga i n : \User s\ ADMI N\ Des ktop\My Drog,·arns>
Syst en.out. print ( 'C!r cv! ar Lir ke d L!s t afte r de l et i on : ·•, .
li st.d i s l a , ·
I' l
- - - ---tt-----l..J..L--±f~3 e_ · 0.:J..o~f~JD-~
__:_J ~oJ ._ . . ---
!r----"---'-='.J -L~- ._C_)__;_[l,.5 pICL'j i;h-1~-~ ~ i - f '_ _Q___ h u. =-a -=----.
_fu[rt.J · · -
-0~-bc, ~ l, ,e b: Acl cJ 1u.J 0
- -- - ¾ -~ ~ ~ K f._
- - - ~'1:5,Kh.ecO:u.lurS'.rrt
O LL!'..i'Y'--1:Li,(')
-tt--1L.l~ ~ ~·QJ_
- - - - t t -- ~~'.JJ-f ~u_1QQt_ efb{)f o t1 J 6 eJ.u(_f)__s :{b£ ~e3~w J , -~ -- -
l,2--'
.LL1
- - -~ -- _[ e ~c>i-yJ.omioJ 0J c•
• ,i ~en t \/ rF . .
f _cl} 'l-~ perc,Ltio!\· (' k-J3 : · ~~· ·~
· ,' s: Cf m @6Jl~ rr.t C'{[c\c_e-£.1£ ' -
tJS£~ - -- t - ~'--
\ .
! . '
)
- - - ----
~;f, mynotes
" "L
I
Mt Kn..,wh1 t1ga bJnk
1
{;'7 i
lr==,-- - - -
I -- - - , -
_c1~s~-- __(,arq_fcl§W~e&_;sLr -
f _ _ __ _ t·d odf) ~ Qctdl ~n cJ 1- ~ .
. - __ . ______t_b d_:e_ _ffiI f _;: ~ (-1.JJ _; _
_ _ _ If ~~ect- _ /2alj YJ.Drf1_icJj
_3 _ _f'i..£W ___ teffV1__ , n -ch e:
_ Vo ,d __ r-n _<Joci,£..it11 __ Coe.JJ,·c :e~ , 'n{__P «_poFi e~k lf
I - Node___ 0£._u_J_J\j_C)_J ~ _ ::_ _6'1 P~u_f\l C9d {: __ ( C.c:>_e(f ,c_i enJ J _eK f2gJe~
- - __
~-
of
l--- ~+
-
-:- neWJ\b d~
~tt
=
- _A2::
_f__ _ ____~- --, ·-=--=· -=----- -----=----
I bl"' newN acle ·, ·_~- - -
l ·np;lc1.;_ ]~fl!..-l'r-1c,'r0 7/72 r'l{"cc_Jc110"ler fw__e
tcoU, cnpre) ....
- ~~ 3_ ___ ___ _____ _ _ _ _ _ _ _ _______ _
- - - ~ - - -- -- - -- - -- - - -- - - - -- - -
_ __,_//_1?_
_,_ 's_p1D . #H- po½~o6YJ,d_ ___ _ ______ __ ___ _
___ Ym_cl ~ c~rsp)c~tj-{J__!- _ __ ______ __ _ _
,f (hec, d =.- ncJ f) [ _ _ _ __ _ ____ ___
- - - - - -- -- ¥~u:l p-1l: ia·U Yl
_ _ _ __ _ _ _......,,_
~ -"=°ed-
'--=-
rro l':J-,0_01"".)i_cJ is P"fiJ ,, ~
u.,-'-"'-
6__,__
Y\_,__-4-
; - .. .. - - - - - - · - -- - - - ·- -
~~ - .
_ _ _/_})[ode __.Lu.f_o_ed.__; h.ea.J ;__ ____ __ -- -- ----- - -
f- ~ --d ~§FYYI ,~ uJ- p.i r,3 Ccc:~~ P;t .fc,p,r~;~ pre{ -} -,, d{"~ ' '4 f
_____ ~ - · · - . - -- ----·- __(_~f..PJ\t • .e~pe¼'P~);
__ (Lto 1' rrt_~ ru_((foJ_ ·neae_{ ', ·
i r (' JcroOl?Jc/c ! =- hPc-d ) r
f - J ')31F tY1. 6 ,,d -P"'"r ( '' ~-'') i
'-; .== = == ~ J~ ==---=-- --
ffijl, '~ ~
============ =====
- - - - - 1 + -- -____j Co >h fie ( ('~6",pfl± ! ~ heacD) :
Sy ,s1fm . C)uJ ._pJ ~'01 f C)~ ______ _ Y\
. ' I
- - - -- - - - - - - -
~ . - ' _ _ _
- - - ---tt---- - iITs:«K.~ I. (D~.ffiw'd:.,1 p l.e,qianeait~
- - ------1,+ ---
/
::--+-----,J!I_JJ
-------,---~_J___:__ . e~ 0 - - -- - - - --
- - - - - - -- - ~~ - - - ___· _ - - - - - - - -- - -
p2- ~ P2 . neckl ·
u, ~:iowlea~• banl
11
·: ---'--
- - --- - ---r'- - i - - - - - - - -- - - - - - -- - - - -- - -
- - - - ---tt-- - - - -
(.-=
.eJ
'--
_U _ ·o' , · - ""~'-'-
'----'o'-'- .p~ ·s uJ
~ ~,--•
.___-JJ.-_· - - - ' - - - - - --
~ •mynot;i
[
ll
('1,1:t I
(~11,i Gg J
-====-z - - - ==== ==== ==== =- -= - - -=- - =- --
--
- - - - --2 ~l buc C ICL)-3 ,~c) ),~\ lD CHY) icJ C 12 e /[ oi j tJ <V3
- - -- --- - - -- -- - - - - - - - - - -- - -- ----- - --
[ifcC-1.-hoL¾clLlsl~)_p_olJ' .:: ___£}ew_c,L£e__uk1.LL~~hed J isi C2 j _ -,
-- cie-Jlt5i pciltf2 ::- 0 t' r i:2 _c_, cc u A~ _()__h_d_Lsi._()j_
- ---tt----- _[' r( CcJ o, ( Li _
~,rct-d~rLinked-i~~-b Y-es~t1
- - - 1- 1 - - - _
- --tt---,.--"--_ _ _ , _ _~ ~ . lr-- · -
...!....J.<.LbL - ---
Ca--.SI? J: - .
Co...~ e C_\ -
1
/ S~_s frrt1, c,~ ,f--Si~l ' fd'\;le~ _ ' \~aJu~ cf riA _ro~ poJo/o(}) ia)
- - f ~ ,, ) ; '
a I :::- .S(' ctn ~e f. ,n ead t6\{ C ') ;'
t' r1{
_ S'f.s7em ·OLt :! , p•iri/KJ { •' fiPsccl i-_:_ ''1 (lo l'J 1 • ('
\lcLltta:k{~1));
boeqjc ; ·
C0-312 7: (.
S rgfe/!Y)• 0J •r 0irt- '' f,nh vaJue c,f ;r: ~ p1,y0ar>'!icJ?:
,' rJ 6C 2. :: 3('q<)d")t'o · 6lecei1al, ()
; ") j
3p ieyn~u~··rx~f\i ,n ('rR~u !·~ ', '1 i pch;?• e,rcl,~(lte
bHtJ~~
r= _ 2
_ tt );;
II
'I
i
II
•
,1
II
- - - - -- --=-
- - - - r t -- - - - - ' - - -- - - -- - - - - -- - -~
f t -- - -- - - - - -- -- - -· - - -
lt:~±~
_ __;_ F·--t+-___,,__,::_~ ~ - - - - - -~ ---..·.•.:.. _-· - --- - - - - - - ----
l
- - -----++---...c._ ·---"1~nc.J_t;~L~ ;0 (-2~)-M-ct).1&~l _,__'_ _
~ Cl.!MLJJ.
°'..:u
Ji-"- J~
. .:. . iC.&c 2_~· _ __
..£= _ __ _
- -- "-'...µ·i..i.c,cec.LCJ,__
-+t---:,.L-~ ~~~D._~~~L_Q;O9 _;_ {)'-'-'C)'-m i_
. ~l_:_ _ __ _ _ __ _
.. r-·~ncmioJ- ~ - - --
- -- -- - t t -- ~ ...:..._~ ~- :f,,::.ill 610M \ o);r ·· .,
- - - - - - jf - - - ---'-"....!...___j~ ~~ __J - '1~~cJ.e__,_·_·- - -- - - - - --
~_rtl_~o,01 'rcJ 2-
- - - -
- -- - - ,~- - - - - -
- - ---
=
,,
~~ 1 I )
- ====== =~
--- -=-~ 1,-=== E , ]_ I )
--l+-- ->=--'-=.
1':trJ"""-1.-.>1-~egrr
, __:,. n IdJ p~ C'lc?J:'DUk~cJ y___'L
==--- - - - --
-__ _ __,3_, _D, ,f-J ~ - P-altno-~Ld _,, --
- --- , LS-f-l~- ~oJ~C)_m.tcvl_L2_ ____ _ _ _ _ __
--- -- ---ll--~--Bd-d ,{)_~--!J_CJMl_oJ-Lg._ _ _ _ _ __ __ _ -
-- -·--- (;, E'C__cJ_u_ade__p&J~ J,C)L cJ ~ ___:t__ _ _ __ _ :-....:._:
rY\l'.._h l
- - - -- -----
- -- - --- - - - -
c.oeffici
: \Users\LEICM >\On~l1te\~sl ctap\prav-\jav ii>j~
u:.
. int · ellJ)Ollent; • Insert t - in Polynaaul l
. Insert t - in Polynaial 2
•13 . Node, next; . Dhplay Pol,nalal l .
', · NodP( int ~ f f . Di>plq Pol,,,_ial' 2 ·
this. COl'ffici . Add Pol,-a-l5 ' ,;;"
1 t his. exponent , - ~-,;.;..:.;. . . Evaluate Polynaial' 1
· this . next e nu · . b1lu1te Polynatal j2
}, "~ . Exit • '.'
nter yaur choice: 1
.
ll, . r eottficimt: . 3
c Jas~LCir<ularL i nk er pPOllfflt: i 2
· head = nuJ "t'r~
--,. tail • nul
I~!. ert a n • ~sert tera 1n
Polynoaal' i
• Insert ter'II in Polynoaial 2
17 insert( i nt . , )
. Display Polynaial 1l]).J?
11 . netftlde - nc:w,NQd coeff ' . Display Pol,naial 2 , · •
19 if (~ad= n . Md Polynaals ; }(~·:
ad= • Evaluate Polynaial 1
21
• Evduate .PolynNial' 2
'21 ail = : :,,~· '
• Exit
ail.nm: er yaur choice: 2
e { er corfficient: 5 ·'-: _
tail.
nil•· rt~ ~ tj ~- :
tail.
• I~s~rt t - Pol~l'1 . m
t • Insert t - in Polynoaial 2 .
. Display Polynaial 1 · '
} :~:
Display Polyncmal 2
II Display t~e polynoid.al
c
.
• Add Po1~1s . : >t .";rJ:'
1\Ii
• w id d1s,1ayo
. Evaluate Pol,naaialj 1 ~- · ·
31 if (hNd_ - n~l. l)
• Evaluate Polynaial ~ 2 •. . _i _.•.·_:
32 • Wt ·~:~W, \,-,
r yaur choice: ~ - ;,, . ) .
3J ~.out.~
~~§ , ...
1
I
6. Evaluate Pol ynomia l~
68
7. Evdu.ite PolynomiaL 2
69 . current. e c urrent. next; 8. Exit
70 } whil"' : c urrent I= result .head); Enter your choice : 7
71 Enter value of K for Pol y no■ ial 2: 3
7 ') A~<.ult: 4A'i ·
· 93 ~•JJ Uc class Po lynomialOperat ions
, : aaaeaJ \
94 •;ublic static void 11ain (String[l args)
114 ' case 1 :
.~ • p2 .next; . . .. '1'21 . . . . _br_e<!~ i · ·
,nile ( p2 " I • ot_hei- .hea4 );
System.out.print ( "Enter coefficient: .) ;
122 case· 2: · H)·,
123
·"~-·n result; 124 l·nt coeff2 . scanner.nextlnt () ;
Syste■ .out.print ("Enter exponen: t ");
I I - •.. 3',; the polynomi J. at a given value of x
125
int expo2. scanner.nextlnt{) ;
_int e,aluate(int x ) { 126
,-.: result = 0 ; 127
poly2.insert(coeff2, expo2 );
·.:.-: ~ current • head; 128 break;
case 3: . l : '"} ,·
Syste11.o~t.print ( "Polynomial
result+• current.coefficient• Hath.pow(~ 3e
current = current . next; . 131 poly1.display();
-.'1i le (current ! = head) ; 132 break;
Ca se 4:
System.out.print( '"Pol)lnom;i.a· 1 2: ") ,·
-~: J·n result;
• 135 poly2.display();
• 136
break;
137 case 5: .
: . ; , s Po~ynomialOp Ecratio~s· m • 138 • · · result = poly1.add(poly2);
~ 0
.: static void main(String[) args) {' 139 Syste11 .out.print( .. Resu 1_tan:t P_olynomial: ·);
~canner scanner ; 1ew Scanner(System.in);l40 result.display() ;
~i·:ularlinkedlis t polyl = ne~ Circularlil41 break;
: i ·:u l arlink'edlist poly2 = new Circularlil42 ·
case 6: . ") :
~iccularlinkedli st result; . .143 System.ciut.pr~nt( "Enter v~l ue of l( for PolynO'l'i al 1 •
162 \