DSA Assignment 2
DSA Assignment 2
DSA Lce.b -
( [) ' I )
' '-t -
r~clciLccJ__ f) ~ ~
s io D_!n ~J;1 _-- Q__ (1•..-1• ,, IY
- - 1- -
1
--- -
----:::::: --===-=- _- --===-=- -: _- - - --- ~ - -
,- -C-/as { _Si''(l!,JLin} f'J lJ~
I _/\lode head=-_nul{;
t - ~taicJ caecdE' ( ,01_ clcu-a ) /) eoecJe J sb1
_!._
_ _hectot _~new -N~-cl~ (da/o_)J._ -
?r - ---- ·- --- -- --
-- _ I ___ _ \/0 1' cl j,\_S'.e:,t Cr'~LdWJd)_JL~"~e<b ew nod e
_, etu('0 ;
j .
I~,~~
l 1'.;""C'
.,,. ,('•
.. , l( ,_,,.I\ ' ~
I
I
I
Da-.,; . I I
P1~~ !9_)
- --~=' -=;r:;=~;;~,nd :c hfod; ~~~-- - _ _ __
___ ~- ____ f.y_h_i_ l,e _-4_w££fi ·n~eit-!J1c~I _0~_CcJfrenf. ()eoet• c}cdc)i
- - - - - ------ :..!·•~,::: cJcdb_)f __---
----- -
~
I
--·- - - -~ - -LL-r£e__a-J.__ ::- (u_cre >1_l~ rJ e~t _,l _ _ _.
- -- - -- - 1- -
ed;
u r~e nA-··dee.le, +'' -> ~--,---=
---- -- ___
- ----\.;\ === ====== === ==== ==== =======
- - 1,
. myno!J3
_..:.._ ._ I
Ii >, ., ,l! j • j 'J) .\
l
[L
~,
A S1'()8) 'i l1nk:PdLis1. Ii)~ ~ n('~) /] i6'gtl, linh·d [ ;,;lr );
b C)ei re ~'() e.x/ t ::- r('t_ 1<:>e j
WrJ,' /f ( ! e<Je"rt ) / ·
1
_ 6'_ystPP">•_0ul •_f rin,f}J, ( ' 1D hf)e t'iu ");
!s~ ferr1. o LJ · pr_;d1J In C "1 n l ~ C-oea:}f> o List :
");
. _ _____ _ 5Jsfeff_)·_Dt_t1· p/ ~JI) ( ~' l~ 2: J!)seef"t o 1'bcle: ··);
- - - -- _gJ31ern ~e_ui 'f[ 16Jlb L'' 1n3- ;_[)e)ei e t!f r od1
1 e: ~ , );
:J°' 1( DoplQ1 CJ 1'_Q_cte:
1
y~
__ __u_'--+- {_·'_[ nte o dctfet _ic
-- . au l:-f i n.± _
s+'-"'em 0
Q • Ct:eo1e J ; __ _
,·s L: _" -) _
tno1r3.__L• n&;e,t J f\l ( )_;
- - - - -'~oJ_{ _('__£_e _ ~_ -.: SCc
_____ i'n-L __c'["eak-Caeafe_DaE-0; -
a__ 1ith
_ ____SJrleM,!' ocd · 1P<1_ntl ~ {_'' L,)_l)_ c-fecded
___ __ L1~+c, _'_ '± Ctft'cct~D cdcl JJ.
__ _ _ - - ~b...-~ecd< j ----
Co YL 2_:_ -- ; ;, L J - l . 1
1)
22..
/
I
-
{ ClS e _-~ - - -- -- -- -
_____._ - -- s :Js +e{"\ • CJ c._1-f- 0 r ni
7) ;
-+t-
- --~ ---
?_ - -_
----------- -
_ __ _ _
- ---
--- ~
-- - · r o, n -q er. c Jr, ~e c '2___; ____ _
- tH-D--- - - -- -- - - - - , , < . - -- -- - - -- - -- - - - - - -
- - - - ; ~ 1 - - - -- -- - - - - - r -- -- - -- - - - - - - -- - - -
--
~ I
r--=~~_,,___,,__~
!- ---r-- -- -- - -- - - - -- - --
- 1---
r.iyr,;i•35
_ _J
i Zt?n&oit#rt 4r..,,, i¥
~/)enLt :
1. c'l)ecde L,st
2 ° 1nseob J\J ~ ole
J · Df leie 1\f c cl e_
1:1 · Di~ pI°'-~ Li q1
S' · _fee il _ _ _
Lf'..Je_r:u)_: ~ _ _ __ _- -----
~ J !__ _(_~ Pate _____ _
g ·_ I 6'_seLE
_ 1o c,e
[leJ e1e Jjoole_ -~-~---- ~--~-~ -- - -
_ j _~_
I _4.__ ~-l~p liLJ Ll1k __ · .- -- · __ --
5-~ t.2e11) - - --- --- . ' ------- -·_· --
-- ----- - --
E~ _ yat\'{ ch (')let : 1r __ _ ___ _
L!_o ;~ed - hst _ :__J_ a ~'>3o~)_n~_1_
Mt'12 u__;_ · _ · _
)~ {-rect:Te · Li __
1
! ..Z ~ 1nser_5 i'L~ e,}t
! J · Delete 1\)ode
I+ D i9p IWJ 1-·1s b
5J foe,b. -
f r-ir)ef c0o ,ce _
') o u 6 : '"2-
FYlrfl--r c-J o[Cl tD ;'f'~ea-15 ~ Lt 0
Dc0c1 ~o f~ )eirb ~d.
I )
I 21, )
______ t 11enuL__:.____ _ _ _
/ .,,/c__-_ _ _ __ _ _
,. / ----- I
-- -______J~ -~J...)_L_~_!___::::::~?_ ________
- - - --!J.. - L . : ' . . - ~ ~-,.L-
. . L1- - - - - - - -- - -
lk:'.:.l- - "===01.,s:-U-
&-Le--'-1,...,_______ _ _ _ __
~ r: Yo, x< Cheree·. 3 / ---
- --~_,_~c~ dc ~{
- - ---+!Ji ~ --.,L-- - - - - - - + - 1j_e_DJ..L: _ _
J. c _ 1• C~£ct1{' Lish -- - I --
2. I ec12 T\ 1eck ____ _ .1. L
_ _ _ ,,a _'._ -,l . . .,Ll. . .___,!__~ ~- - ---f----'-d~J2elete 1)'~
1,. J~· plc,.y Li s:h -i -•--E1~p !<UJ DlD_~-- __
· l:::Kit _ _ __ _ S:u tx:,:t_. _ _
1 - - -- futei( 7\Jc4c ChJllce_:lr_______ ---- _£(}t;e_'C _'j1'Ut ___cb_ai{19)_5 \ -
--
- - - -- --- - -
'·~• ·,.lmyno'a3
• 11
~ .1:-J_: • ~JN
t 8rt j~Vi,ul\l.Scan"t,;
0
111 uc,, 0111 c,01.tt,1n11c.nttH1•0-10t-Ge
ch&I Node { r,eoOtl"coo t • Tht nkCtnt re. ~•o• Sot, Cu. J , $ ,,nc LtnktdL\stMl'lU
tnt data; ~cao1t11c.01- rhI nkCtntro•MO• 50t•Ctn, ); S jtv• LtnktdLlstllenu
Node n,xt;
Nodl'( lnt d~U){ 11tnu 1
thU, date = data;
tfl\s. ne~t e ,,1\I ;
l, crut, L\st Menu:
2, Insert Nod,
3. Delete NOdl! t. create Ltst
4, Dlsp\ay L\st 2. Insert Node
S, Ex\t
cliss S\ng\yllnkedllst{
Enter your chotce: 1 3. Delete Node
Hod, head c ,_.1 ·. ;
Enter data to create \\st: 10 4. otsplay Ltst
L\st created wlth data lG
vold create(\nt data) /.' create \i~t S. Ext.t
{
head ~ new ttode(data); Menu: Enter your chot.ce: 3
1. Create Llst
z. Insert Node Enter data to delete: 18
vold \nsert(t.nt data) / / Insert i1e1~ r,ode l, Delete Node Data 10 deleted.
{ 4, Dlsplay L\st
Node ne~Node = new Node(data); . s. Ex\t
\f(head == rid 1)( Enter your cholce: z Menu:
head = newNode; Enter data to lnsert: 39
,_ )else{ · Data 39 lnserted. 1. Create Ltst
Node current = head; 2. Insert Node
·· Henu:
wht\e(current.next I= null){ · 1. create Llst 3. Delete Node
•
0 current = current.next; 2, Insert Node
3. Delete Node
4. Otsplay Li.st
4• .Dlsplay Llst 5. Exi.t
S,Exlt
Enter your cho\ce: 4
Enter your chotce: 4
Unked Llst: 10 •> 30 •> nun Ltnked Ltst: 36 -> 40 -> null
vo\.d delete(t.nt data) / / Delete node llenu:
{ · 1. create Lt.st Menu:
t.f(head == nul1 ){ z. Insert Node
1. Create Li.st
Systel'l,out.prlntln("Li.st is el'lpty. "); 3. Delete Node
return; · 4, Display Llst 2. Insert Node
S; Exlt
Enter your choi.ce: z 3. Delete Node
Enter data to lnsert: 48 4. Di.splay Li.st
return; Data 48 lnserted.
)
5. Exi.t
t1ode current = head; . .. · . llenu: Enter your choi.ce: S
wht.le (current.next I= ,,ull && current.nexf.d, l, Create Li.st
current = current. next; Z. Insert Node Exi.ti.ng prograM
J .•· . 3. Delete Node
\f (current.next == r.uH) { 4, Dlsp\ay Lt.st
Systel'l,out.prlntln("EleMent not found."); . Exlt
)else{ · · · Enter your cholce: 4
s: current.next = current.next.next; · llnked Llst: 18 ·> 38 ·> 46 ·> nu\l
}
case 3:
systeP1.out.prtnt("Enter. data to delete: ");
tnt deleteData = scanner~nextint();
li.st.delete(deleteData);
systeP1.out.pri.ntln("Data" + deleteData +"deleted.");
break;
case 4:
systeP1.out.pri.nt("Li.nked Li.st: ");
Hst.di.splay();
break;
case 5:
exi.t = true ;
systeP1,out.pri.ntln("Exi.ti.ng progral'l ");
break;
defau'lt:
systeP1.out.prtntln("Invaltd Cholce. Please try aga\n '');
-- ·- . \I -=-=--
--==== .::=:=-:.:-..=::=.:.::.-=---== -=-=-··.. ---::.:--::-_ -: - - -- -
'L1 ✓
G.1 ~ Tl~lc .: - 5~ J-- j_j ~ked _l tS' ± _o _
____ J __
---
____
- - - - --
- -
H- -
L
I ~ '- r__TA_Ji~tS' -Cf.~s. t.lruu
-
--- . . . -
_ Cdn~aJ~__·_me:fb_c)d_._:t.o__ (lp.~(C<de. __
1
______
11
_oD__J....\-t,_,-r_ r: , L eQ__
ilJJfi ..J t • } • ·
1-r 01:.r-- -- --- --- -- - . - --- -- --- --· -. -
~l) :_J...'Q.1i LcJ1:zes· ..theJ r'si ___w.i!J_ ,._ f{Sincrle ~
11 1
.l . _C(tbl(_d(rb_
. l\ irs_eni( ;nldnJo.kti.ctl ~ . . uJeJJl_f.lQo/e cJ_tht EDcLcf {».e IZs b-•
-- - ====- I'.)====== = = = = = = = = = ==-:
- . ----~-
--= .. --- -
-=-~--···----··· .
i
~ ·,: r ,).iH 11
' . . ... - I
Wi i '- 'IN'""., t "\ !!
L
Ii
)t - --====-
-=.\_ ceveosc j)_ :_R~eo..se {½e l\cfo·r of "'lr1cLr r,Jiih the
,1 <J;"pn c/c~te1 ezrc'Sl5 . -
cou"tcO : [o t•ni the. n~!YJ!Jer --- _<2-L!~_cJ€_.g 10 i -0-J e It~,..
'1 _
~ cl is plet3- n: - p0 Ll}_L ---eJu.t -CJJ r- B,-i L Jlt'le"f_es l f\. "the /i'st,
~--* -- - - - - - - - --- --
~--=~,- - - - ·- - ---
~ J_i ~- - -- -- r-
___ ___ ;_~{20-~b · j at Va • u i /.
-- - - ,~ - L~ ~r ui £-~·~?--,_ _ _ _ _ ___ _
---- -'/\lo
--•- --H ~-~-6 ~ /
le!Jr:6 ;._ ~· _ _ __ ___
--- - .J+---- -N oPe Cidlt dcttCL){
- - - : -It - -- --
a D--1--j__ __ _ __ __
·2 .elcJa ~ da±.~
· - - --- - -- -
~ - - ~ - -- - ~~ ~~ i~-~~n~r~J~lJ~
---:7
-. -. .,y~-:ls '\i ~
"y <·;;w" •' ~rn
}' "( t ci : () ('Cc) I\ lode ;
1efre F
f\ lc>ere co-rft'rri : h()nd ~
uJhile {cur,r41i ·a"Yit6 l -=- fl tLII) f
Cc.troe rvt -=- ( urre.5'[5onl'cc.t j
~
( o c{ e6\\.~ f\reeJ :: 'nP0 Noclt'1 ~
~
½ I -- -
\fo1d oeveoJf JJ J ]ev{!rse #P l\~t
l -- -
NC)c) e - l1)'ffY ~ - uJI ~
f\ bcte_ - J_ _-=- 6eq_J 1
l..-b-l~ f;
0
II (, ?~ _J
------- - - - - -
-++--- - \ - - - -- - -- - ---
I
- 1
r - - -
, I I _J
( No_ . 3? - )
- I\ ==
f:,. ' 33
-==---= ====--: - --· - -- --
" 0e_e1pc_ Lf_: _
•I [YI PoJC. l ~
.. - J!J_(6"t)cJe . Li st- . __
•1 2 · l ns ~cb f\lc,C'Je_
.
1
J ·__ Pev.e~e. L;5-b
j Li· 8 Paoc h _{\)Qde_ _ -- _ ------ ·.
I[ S ~ COCJ D 1-J\ r e>cD_p £_ _ ___ _ . __ ~ _ _ .- __
---------
- --- -
- - ---
-- -- --
r-
- . f.!;1rnu ', ~- ---- - ----- - - -- --- - - -
. r, Cceate - u'st --- - -- - - _ ___
,___ g . ~se~rs-!'lod_e_/ / _ _ _
-· -- J_~e_(SE • - - - - --- -- - _
_ _ ___ 4~ ~el'.21 _ _[j o~d_e_ _ _ _ __ __ _ ___
_ ____ __ s~_ _a @ __/\hcl~e__.5___ ___ _ _ _ _ __ _
______ r;_, rr_s ::2l o..y L;s f;_ _ _ _ _ _ _ __ __
1
- .. - - _:]' [ ) ~)'t- '
-
J
- - - - -- - - -- -
- __ _ _clt1__ i )tiu'lf c hc>iLe_';_J__·_ _ __ ___ I __ _
_ _ _ ___ L;s_t ~ (~e-ve
- +-'~~~~e~d·~ - -- -- - - - _ _
.. ['-J f' Q! LL ~-
_ !_· C'cpc:Je__Lls~t- - - -- - - -- - --
_ _ _ 2_~_fu~ei1-~-D-'o~d~'e_ _ _ _
_ ._ ~ _3 J fV_fi~S?__1J5_[) - - - - -- --- --
- _ ~-· 8PM4k ___Nocl"' ------ - -- -
-_ s · c~unj_ __:____,f\!__ _c"-"oP
_ _,_, '--'e__.
- r_
_ ______ ---·----- -
_ . _ ~ · j)'J_S_pf_R'J-
, lJS . 5 - - ----
7, -E~ i ___ _____ __ __ ___ _
myr.J .
-- --- - -
1, --- - - - - - - -- --
1
--- ·t -
jl__
I
I
b , &-°-=
-
_ -- _ - ---f+---'---
1fl'---'f)----'
<- ---Lt. {. . .p_.'___- --- - - - - -- - - --- _
- ~-cd€~ ~ - --
-- - - --- - - t t - -- - io1 ~--'-------,L..->,.___-
2 ·-_-=.,c__~ - - -
€. ~ r-8-~__,15__,___ _ _ _ - - - ---
I --
-• - ---
1
- 1,
- I
· ·· rnp~\3 ;
[
. ,.. .
M"t l
'I
-w .... ,
:
t.Ut•,. t).tl,1i
, : .. -., • lh
~
">1,-b~t.,,f,tht I
t•1
to I
II )
I. .
,...... ..... ........~ ...... 1:
ft ~":"'~ :!fl \I
", .I.,.-,·,
n - . . , ~ -~:
" . ~ _l,.'i, (""""t."'""t
°""""'t•<.~1.f\..'-CI ;
,a MJl ) ' I
I .
ti~:".+
oJ)
' it:
J linkedListMenu.dass
J Linkedlr..-lMl.'nu.j<lvo
b::J WhJJ.t• \ l~;U.t } t
J linkroLislMenu.java · X ·
l1Nw,
, · !4'.J:~~~;;1r:,i;..~~{ 3& system.out. println("\nl"..,nu , ");
1~. J Node.d.ls>
J SinglytinkedList.c~
ill
es
,,,
system.out.print ln ("1. create List .. );
system.out.print ln( "2 . inser t node" );
system.out.print ln("l. Heverse list");
1. c.:reate List
? • tnscrt flodi,
3. Reverse List
11. search riode
'! J syst em.out.println("4 . search !lode"); 5 . rmmt Urnk•~
syste11.out .pr intln( "~ . lount llod-,s" ); c,. uisplay List
syst em .out .pri ntln ( .. b. uhplay List" ); 1 . rxlt
system.out .println(" I . txit" ); Enter your choice: 4
system.out . print( "tnter your choice: ") ; Enter data to search: 20
int choice ~ scanner . nex:tint (); lourd .
0.,1.1 7A