KEMBAR78
DSA Assign 4 | PDF
0% found this document useful (0 votes)
27 views18 pages

DSA Assign 4

Uploaded by

Omkar Kumbhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views18 pages

DSA Assign 4

Uploaded by

Omkar Kumbhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

- .

·--. - -· ·--· -···

.... . -- ,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
- -

__ _ - -2 ~,o f" kL II ~ _-~_e _ -1S _ n u)) - cJ


DD- 't{ e
end -) Ctr) ou.1; ~i - (o r·J ,'ri o~ 't:fCA''ft .3 a.J '
- - - - - - -
- - - -- -- - -
·t-- -

- - • 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 :
- - - -- - - --
__ _
_

_ ___ _ -') _tj


eJernedOo.<2.0, 3o,4 a) : Pclcfs elem.e..nf_s {o lJ,~_ _
ii .~s er~
C'}r culo .t Un keel risi . _ _ __ __ __ _ _ _ _
__d_li ~--
__ _ ___ _Qi~-P-h~c j/,e Us:,k :~ 8 .bD_(Y- +be r~ffe__,J -~h_Jp
- De2efe. _a·n [ff.0 .eni _f_~ ol~- ReYo\6'_Y._('J:__j£ p b..~ Q,; ~_r d{ e: =
-- -- -- ~1) 1.s_p !J _ihe lisS ccJ-nir') :r -3.ri.C)tQJ . °IllL _J1s i aF1.£.L _ __ ·
/ : _ __ del cl- ft7- -±/\e __ hmci_. _ . _ ______ _ ___
_______

- - - -- -----
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

. r P( form Or f'o n_1;{~Q'5 C) cfi I °t ,.

'!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

- - ---+1- -- 'f __,_<~fF----=-


~ ----'s=,:='---r- m --'-----=-.,........ tB~p_c1trriJD -C ,'r Iemerd: n(jv ~!Ml3L" ;
o '-->--<
7
. '

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

Node ( i nt data ) , l} Node current• head;


this .data• data ; 3, Uode previous• nu ll;
34 I/ If he ad need s to be remo Pd
t his.next • nu ll;
35 i f (head .data• · dat a)
// If there ·s o nl y on e node I n tne list
s 36
Q 37
38 i f (heid . next hea d)
10 c l a ss Circu l arLinkedl i st
3q head • nu ll ;
11 Nod e head nu ll;
40 tai l • nu i l;
12 Node ta i l • nu ll;
41 re turn;
13 // Insert a node at th e e nd
42 else {
14 voio i nse rt ( int data \ [
43 head • head.next;
15 Node ne,:Node • ne1-1 Node ( data ) ;
44 tai l .next• head;
16 if ( head •= nu l l ) { re tu rn;
45
17 head• newNode;
46
18 ta i l • ne10Node;
47
19 ta i l.next• head; // Point t he next of tail to head 48 do
2C else {
49 previous• curre nt;
21 ta i l.ne xt • newNode; current• current . next;
50
22 tail = newNode; 51 if ( current . data•• data )
23 ta i l .next = head; // Ma intain t he c i rcu l ar nature 52 previous .next• current.ne xt;
2J /
53 if ( current•• tail ) '
25 54 tail• previous;
26 I I D~
/
node by ,: alue 55
27 y .01d delete ( in t data ) { 55 return;
28 i f ( head•• nu ll ) { 57 !
29 Syst em.out.p ri nt l n (" Li st ~s eTipty." ) ; 58 ~ wh ile (current ! ■ head ) ;
30 return ; 59 ;ystem . out . println ( " El eTient 1ot fou1c.· , 4
31 60
Node current 61

C· , ~cp J r,..t a1n._1 cva x

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

_ _ __ ~ _]J 1 l_e__; _-_ (,__r'6"Cc.JCL r __ L; _o J-< eJ __ __L ;~ _---- -- - - - - ----


_I -- - - - -- - -- ---- -- - - - -
____! I __c,~ J_pc};y~ - - ----- ·- _. --- -- - -------- - - - -
------ I I ~ Ta_, J j_QoLe~o_od C('tl'[:;o_ _d _etlC!_ 5vres · ---- - .
- - -- ~. _u~
clues ±n r-c~- ~2-P--f_\__cali_c;o.) __ _o£_. ci_€"C.c_Jo£ _L, nkec~ --
- - - -- _LJ_$±__1_n __ f-al~~_C!)3-cJ __:QLJ:f2ITssio_o_. - ..--- __ - -- - - ~ - - --- ---- --_
_ _ _-rt ] §o.bten-i__c3+c~e[r)eJ_s .: ~ _ _- _ _ _ __ _ _ _ __ ___ - -----
1----- - -1-1---'---"'": 2 JL.__!lf2i'.)_lf.e,:ud . P01:[ " C!_
,-.,icJ {U CL- t----i' ~ j
_______ _ ----tl------'---Lr
:...__:____;
i k "-l.....L2J. lJs~c~n d__ w,_6".it:e.___ c,. m enL.,'-- · o)<,vP() _ r-'("~7 OC' rri :.t o_
Pe cfory71 a- dol ,·1;oo1 ~ £ ~o__f_u_u_dl_oS) "~-
- --41-- -'-'A- -- -C}_uJ_o,__l'.:'.:) _f's : ~ - - - r
- -- -++-,(~) Ol - - - '~ : : l k . a..,si5~111-,' (9/u ,}c_n:)s____ ___wi If be gJ/,1£.h_=----
- - - -----++_ -_>_~( Q__c_t£C_c..Jc_lL,- li~kd~2.\...__L
_ L...l.:=
t3:!.__l..L_ _ __ __ _ _ _ __ _
- - - ---++-- - "'---~ __e_{) 'CD ~pli('~i io ('\ d Cr·CC'0 c~ y· 1i ffked L S'·t r'al O '1tV1M_1Af_ r
.(>tJ:. ~e.ss ion.:~ - - - - - - __ __ ____ ___ _ _- - - ~
- - - -- - - ---- - - - - - -- - - -- - - - - - -- ---
- - -~----++----'8=--=-ofl_w.n -6P &< H~-l~dw~-re 15 P~u ;,-e me ~~ ·. - · -
uC>hLua..,re: - lJb o rdt-\lM D-()E 'lf~~_ ,_ fdipse_l __.D_,_,____f_ _ __
- ----l--l----J..--}o._<dwci..6'c' ~~ D(?5kto(2 ~ l<f> j f~cAt:d . . - - -- - - - - - -
- ------'-i-'----l--1----~ eeJ ~ Ca n ~e_p ; ____ _ _ __
--l--l--------1--~
--'---.f~f!~ -~ ~ C! n'l ~crb~- -e4.xes__3_1_on ~ ~j &n¼_L'-'0__0 _0 oe
- ----J+...\....._,_::__:____~-'--"-- cJ '""""--3+e'-""-b"----'
c,,c____ -......,.
f r_ t) rn
_~ - 1 i 5 CQ s c__,; &YJ a--P s e veocJ f e 1(m s ~
s - --'J---"-
---- - -----1-1---l..'.a~ "n___'1
._.'..'Q'
:::' --'~r, ' _[~ J____poweir of
--'.._ -f----.:..L!,-j j{e 5 ~ \/Por'ce., Lle_. - - - ---
- ----l--l-..T__l !±. . ._____!_:15'__/ ,e-c•i"p550 r'j- · f o-"' #-e __ po l1n aQ1·1a 1 @c{P-(.~o.e i. _ 6 51-,,
- c_::o ri'I_ ,'sbS_
--i.j........:(7 of__ dv.r-o e Q.£3~s::~=- - - -- - --
- - - - , . 4 . ( __
0
__C~ ff ic)eld_' _pcfi(b___ __ ___ . _ _ _________ __
r
_ _,-j-1__:__ i(__roY)f (\1 jOoob - --- - -- _ _ - - -- -- - - __ _--
--- - - - -
~L,de c) ;;s_~- BE_~_fiifs__ Pc1ch __)Q~~- tn -~ e __
-- _ -- ----++-:-
~ PDkf OD_ro~a.J___w115b._ ('_e2_ef£LC,·~t _a_nc) __R~pon_e<hf , c.~00\ Gl
= = ==-=! ,{efeoo 0c-f' ~ e 0ea:-i f''c e,)e.
~~nynotc:
1-·_-",u - l I
.. , ' "' •It«- .... I
II
- - · l-i O bS_k{_ lheff \cid , ·,6\1 eicf""le"l}_ .' AcJd _cJ._ _.LJ_e u.2 - ef rvi_

- - - ---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 - ~'--

'£1, ~a~ P . eol~ fre' "JioM- --.- - -


-1 ~ . ol d ,s pISyf l "~- Pd'-!/) om'. a ls, ,
~ - ~ • (YIJ_ ,

- - --..-""-I+-'-'-'~ , 'a . 'rwm !Is: d e taJ UcJf p-oi~JJCL'IIJS l'--"'J-=


P O IQ, Q (1 j y-, S.,J.....-'-·..-_

- -- *~+-~Gl. ·L)."o..JJ,a:L!:, oe._e


:f C!wn_:__lLe_
, l.R~>J...ki 9)e I eo[r) s!;Ro-:1--fil_J2 lt' ~ C

tl r' IQ f 0 "-y tO D m,a f eX pie ui c O .


\ .LD,_leJ D
- - - - i t --'-..L-f- -~...1....LlJ'. i.:U--/--LJ.

\ .

! . '
)

ae[fic ied , ;5\4 et!:oo 61 e4Jf

- - - ----

~;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~
- - __

: -- --- __ if lb e..oc~ -= :: n oJ 1)£ ___ ___ __ _ ______ ____:_ ______ _


r-·- ------ heac~ ~ n~-~l~_cL~ · ____ ____ _ ---
~ ____ 4-cJ 1 := cD__e_cub lo_cl e_
_j__ _ __ __ - -
r ___ 1w, . YlPd nf_~~w~L•1.LJfJ., 6l~q
- ---- - -- - -
¾oiUs:,_hl'c:J
\~~---=-=
-

~-
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 - - -- - - - --

- -- - B - - -/ - --4-- ~i le (pf'! & _o~J)_J---


-. _ _ ___ _ _

- -- ---++-- -----'--\ , de Cf IJ ( ~ '[PS u·· J


I0 =-'-'"
f,,__,0""-tC t .,
.
J __, f-+-h ;>------- --
() !ea ri 0 1 d c)ecf ,_ f (j_,IJ. e;
- --1-1----b.--C-'-Lf-_----:;;;. ..----·_ · - - -~ -
- - - -_ CJ.,tL~f'Kp.).n eN ~ "- p<2 • e,c ponerd){ t
---1+--- - -----'1'--'r(c
(Pd• Co efG'c ieJ +;:; Ip z_ . coe{fi'c re Kf ~)
_ _ _--+J- _ ___ _.__c~~c,..c-J~d-t=<Pcb'--}_::::---t-'
{c)~w e__,·_ __ __ __ _ __ _ __ _
btfPal-< ),

--6.J~ ~ .({) f"_(,f_~ ole_d \


- -++--. • -- - -- - --
_--+-
- ----1+---- --\--V..___.-.-'-h-'---';___,I__,e (~c uf. ar_t/; ~~e~, ~~_i_b _~ctJ ); _
----- - ·
_ ][_ ( J ru, dcfud ){ · - - ~ -
- . . _g ;,~ 1Lwiie4 Cp <J: • C effie d"L1 p'Z- _rd)o&t (' rd)j _ Cl

- - - - - - -- - ~~ - - - ___· _ - - - - - - - -- - -
p2- ~ P2 . neckl ·

u, ~:iowlea~• banl
11

·: ---'--
- - --- - ---r'- - i - - - - - - - -- - - - - - -- - - - -- - -
- - - - ---tt-- - - - -
(.-=
.eJ
'--
_U _ ·o' , · - ""~'-'-
'----'o'-'- .p~ ·s uJ
~ ~,--•
.___-JJ.-_· - - - ' - - - - - --

- - - - + t - --· J tvaJ_~J2: . :}J;e


- p~<eiJ · a:!: QJ · ffi ".e() _ v 9--L=1 e ._p
C, ,
"},/>
O '--

ird: evcJ ~e C, ~ :vt 'aCJ -t - _-- - ~-=--


- _ _ _ ___ _
- ~+- - - - ---::·~--_,. , ,_-:--"-,'-/cvf -~ fes01 :: ·o; · ,
_ _ _ ____ -- l\1c,cJe · Cu'6:i-enl:::: he~ ·_ _____ ____ _
-- - - - - - - -H_ __ 0 -tl(ffp(:.
..,L__ _ _-P'f~= t::== __
___ ____ ___ _ __ - - -
0 0£ - . · ·
__ ___ __-_ {e~uJJ_± =- c-~~~{)ht- _E~e_FF,c;er-J~~ -~~-- ~-
- - - ----- --- ,t - - - - _ _ _ --
_ _ _L_Llf ce_
' ' f'l lcd-_~,_ _fb_U)_ ·c~_J (u nferd__ .. fl<~ -
6\t_ _i_.r~ .
_:=_ _( \_ ned _; __ _ ___ _ _ _
_ _ _ · ---t~----=t-0 ~;1e__ fu.Q_
~entJ ~_·ht'~ l 2-;. ___ __ ___ - _--: :
-- ---- -___:'(' e.fIA i:_'o'j .il?3 Y.l ~-➔ · _. _: _ _ _
- - - - -- ~- ___1_
j _ - ---- - -

~ •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

- - - - -r~Lb lic_Sf-D-11~~ _\!QJ__ol _('()$ <) ( .2f.r, n3 [) _OJzj s) r -


-r- -

_ _ _ _ ;;lc~_e.c .5f'ooneL r:: CLe --v Ql"o..a_ne€M'of..9!e!"(),i.!>_);


' • (j

- - -- --- - - -- -- - - - - - - - - - -- - -- ----- - --
[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 - - - _

~ cj' (!q·n netC <D ecll.~y)-t--=-C_)___,.·___ _ _ ____ ~

- --tt---,.--"--_ _ _ , _ _~ ~ . lr-- · -
...!....J.<.LbL - ---
Ca--.SI? J: - .

= ===::: { = ======== ======= ===== ===== ===


.. , ~,ow•eog, bJ , t II
I
~l •· I I )

(, " 11, 001 J

(Cl .Sf 2 '.

S:s.st<? m·.01.~f-p o,"4 lri (. ''[101ec- F,'c-iertf: ,, );


r0 ~f
i f\5 Cae ~+l :- 3 Co.'1 t1 eo, n p oe't Jr.{,(' ');
~,y31ervi , c uA , )9-f ;!l l ( ''['€) t f>-c e~ pc, n r cf"\t: ' ');
r6\{ e~ru 2. C S Co. ri~ec, 61Pod • 16Yt ()j
J90 l~ 'L · l°'Sfob Ccoe'ffQ, eKr6 £') ;
6reo..k ~-
ftt- ~e c3 ~
c'.'\ S'/er-,. oulpo ,6¥/ fpo l'Jlflc,rl'l icJ _ I : ") j ·
-f>-c_l 1\, d r9pI~ ( ) ~ _ ___
b(.P cJ·) - - - - - - -
( rt5 f' ~ : ___ _ _ -- _ -- ·- .
;/ S~_~7fP1·0c.d ,r~,nJ L37 _( ,, p c, l'Jl'OrY) icJ Q . " )
;
_t ol'J 2. d is_pL~j-{ )_;_____ _ _ _
b6Po_J ;__ __. __ ' -· ---
( Cls fl S_~ - - - - - - -- - - -- -
\ ' ( rsult -~ palJr ·., cidd -lrool \ Q_) ;_·_ -
'
_ ~s ~ fe,IVl ·9 wl'--Pr;d.kJ (_ ":_f?~it}Jr, /1[ jo I~.o. o,.,, ic-J : ' ) ;
f r<S u.lb. J _r£ p l c') ~ - ____ _
- ✓ 1S t(()cJ< j '
0
< - - - •- ' - - -- -

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 )

!, - - {IJ (:6'(..~ ~ -- - - - -- - - - ---


- '! - J f d"fo 'teoorQ J,i _ pCJ l~J'.1 C'IM\ aJ I
1

: 2:_ · [.-, in __ U,fr,J_ __ ilfl_ po LJ'11ClMfoi) 2-


~ - - -c3 ' ii.d . DIS'f'lo_T - '2GJ-l'f di CJrvw c-tl -'-- - - - -
I - 1r ·- Q,_g-r- )6-J_ -f-o..h;_6)l)(r)~cJ i_ -- - ---
- -- 5. - f\ c' . . np)r,'\ l\.t
~_{_;J_ :..1..,../- ,-J
r-- "'"""'
1 'dts----
(J_LU - -'-1- J
r , - --- - - - -
- - --G' -__g_ fuD.LcJ 1;2 po hr i1<1>.c'i t-cJ, J - - --- -
____ ] __,_ _£cj_u_cd~ - . ~ )JJµ_C)no_;_cJ__Q_ . - - - - -- - - - --
- _ L fa:_;J)___ _ _ .,______ _
- __ Io-1-e.c.7
~«- choice .' c3
--- - ---- ~ro.~_Q~ ---~ - c.3 ·!JC " '2-
--- -- - --- - - - - - - - - -- -- -
----~~- -Me~~~:___ _ _ ___ ____
- - -· _____L,_-1:ru_s_e_~ ±ec ro i a) P-__cz_lj ()_wCJM
~ lut.c: :_J ___.:_r_ ___ _

--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

_ __ J· [ \rtJ_LLcile JX, \J {) C)_fil~Cl~j ------=


'2_==--- - - -
r . _f.oCJ
• -f -- - ----- ("' 'L- - - -- - - - - - ---
_ __ _ [nt-e.L-) e; u1 c"b cl i c e :1
_ _ ie..s .. 0 I ruP)LQ.]_:,__uJ~arl,:::___tJ1--_ __ __ _ _ __ _ __ __ -

- - - -- -----

- -- - --- - - - -

====:: ~= ==== ===== = = = ==----- ---


Jl'.C:1'1~1 ;;~;;- ,. ,
:~•llonl.jawa X ,
s e . . •
(c) l!icn,soft Corpor.C:ion. All riet,ts reserved.
C: >,Y.~ .>LENOVO >en.o ·
f iaport j.iv-1.util. C: \Users \LENCMI\OneDrive\DHlrtop\prav-\j11va>!111Y« Pol,...t•~ra t ions• ja
· l~~s... ~Ir-t•~~~ i.O?s. .
~ ii ~ e {

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

:36 ' :~ ~ ---:--· ·~ i~


• ~s«rt
~-
tffll~ ~r~ ·l ,1 .
do {;
37 :~ ~ ~ : . ! ,·.L Lt:·~ -• .a.u ru.a.y11ua.a.d.&. .a.
.~ ~,· •. Insert ~ ...J.~

Xi_:__ ______ __ .Insert ter■ in Polynoaial 2


·· if,-;,_:_•:" "2.
J ,PolynomialOperations.java i 3. Display Polynomi;.l 1
- --- .' -· --- - ' ·
·,
C: '$Users> UNOVO Pa fil0peratians:.java t,;. r4.· Display Polynomial 2
>OneDrive > Deslclop >programs> jaw> _,J
30 v"oid display() { • -~ , · #:, :' • . ' .. Add Polyn0111ials . ;.p,Js.-
· ;~,.. i, . . ~ ; • ; • , .6. Evaluate Polynomial 1
do'{ ' ;;;· .• • ·.. • . ·-~"" _;.;· 1 7. Evaluate Polynomial 2
37 ·
38 systelll.ou t.print(curr 1mt.coeffi cient + :'x":'"++ current.exp onent)·; ·8. Exit
39 current "' current-ne xt; ~ • ·! .· Entet- your C:hoice :· 4

40 if (current I= head)·{ ":i:i''Polyn011i al 2: 5x"4


41 · system.0\lt .printC- + ·);
} . . . J,f Insert tera in Polynomial 1
} whil e ( current l 0;i head); Insert term in Polynoaial 2
System.ou t.println(); , Display Polynomial 1
Display Polynomial 2
Add Polynomials
Evaluate Polynomia·l 1
47 II Ac j t~o polynomial s Evaluate Polynomial 2
48" i, Circ·ularLin kedlist add(Circul arlin~edLis t ,·.,, Exit
49 • I Circul arLinkedLi st· result = new Circula · _· · . Enter your choice : S
Re~ultant Polynomial: 3x"2 + 5~4
se· .! Node pl = this'.head; r.::_ '.
51 Node p2 = othet-.head ; · Menu:
5.2"
do {
. 't, ·- 1. Insert term in Polynoaial "1
2. Ins~t term in Polynomial 2
54 result.inse rt(p1.coef ficient, pl .exponent); 3. Display Polynomial 1
55 · 4. Display Polynomial 2
pl = pl. next; .5. ·Add" Polynom~a l ~
S6 1 ~,hi l e , pl I= this.head) ; '.6. Evaluate ·P'olynomi a l 1 ·
57 .,/ j7. Evaluate Polynom i al 2
58 ,/" 8. Exit .
59 ' · Enter your choice : 6
60 . ._if
-~-
Enter value df >c for Polynoaial 1: 2
Result: 12
61 boo lean added false;
62
'ct I
Menu:
63 do { ,1. Insert term i n Po lynoai,11 1
64 if ( current.exp ane~ p2.exponen t) { 2. Insert term in Po )yn011ial ·2
.6S current.coe fficient += p2.coeffic ient;. 3. Display Polynomi al 1
4. Display Polyn omi d l 2
"66 .
. 67
added = true ;
br,;,.,i,c ;
. ,., . 5. Add Polynoaia ls .

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 •

-~:le (true ) _{ int xl • ·scanner.ne~Int();


System . out. println(." \n~\enu: "); 146 System.out.println(:'Result: '" + poly1.evaluate ( x1)) ;
System .out . pr intln( "L Insert term 'in147 break; ·
System.out.println( "2 .. Insert term-~"148. case ·1 :·
System. out. println("3. Di splay Polyno149 System.out.print( " Enter value ·of x for Polynomial 2: • );
Syst em . out . println("4 . . Display Polyno
150 int x2 = scanner.nextlnt();
System . out.println(''S. Ad~ Polyn0111ial i Sl System.out.println ( "Result : ·• -♦ ·poly_2.evaluate ( x2 }) ;
System .out_. prinUn{ "6. _EvaJuate Polyn break; .
154
Syst em . out. pr intln( "7. Evaluate Polyn
153 case·8:
System.out . println("8 . Exit");
154 System.out.println( "Exiting. -~ ");
System;out ._print("E nter Y.OUr choice:
15;, scanner.close(); ·
int choi ce ; scanner ..nextlnt{);
156 . return;
: .etch ( choice) {
157 default:
: ;,,:? 1: 158
} .
System.out.println(';I nvalid choice. Please try again.• ) ;

162 \

You might also like