Professional Documents
Culture Documents
Asig Nment: Linklfst
Asig Nment: Linklfst
4
al! oþesation
Cpvogram to mplement a!
Linklfst.
+indludo stdio,h>
+ incude stb.h>
Stsud hode
int infto ;
stauct node poey* net;
");
pintf ("n ist is Empty
Suetun;
data
J|Paint the ttemb
strudt node
te stot;
(te| = NUL)
while
("adta= 9,d ln"tenp’info);
ptf
pointf
temp -’ net;
tem
int main)
fnt choice
beingin
ILfuncton to fngest in
void tmye st at begeing
nt data;
tout noda * tem þ*trav; (strud no
size
mp= ( staut hode *J malloc (
my next z NULL;
Cant (?. a", 4data );
stast;
NULL
3-f 6tasd is
NULL)
3f stat =
Stat =temb;
nt choice
ile l1)s
"Inlt .1 To see
In |+ fos Lna fion t stortng n';
" t fox Lniertion at any positon lh"
"In t for 9hsesfion at End In");
fox Deletion ol first elemnt In
"In lt
elontnt ln'
In t fo Deletion o Cast
"inlt fox Deleton e pecii psition
"In It To exat ln ");
.a", chaice);
hoice )
sse (0 ;
F t foont ();
at End 0;
t at positon ();
fist();
end l);
þositon ();
1);
tist delete
()
;
clae
st't; teup
þostrtion: tep
* *node steuet
þos,i-
1; tetete ht
þosition) dolit od y
position Dolatafunction t
tte) foee
NULL:
þaew’Net te’
ele
NULL Start
-
NUL) ==het (staot .94
stot = ten
Påntf("C's+s
tmt
NULL) == tat (s 1f
temp ode stut
Endl) delion void
to
End from delete I|fndion
2) ==(þos if elye
þosition
1 134
NULL; next eusnode n
hewnod;
NULL) ==
NULL ==stat J4 I1
"); choice corred ("In intf P
2 positi On)
cludestdio . hs
cludemaloc.hs
But ink
t info
Foud -ink *hest;
nt numbeo;
stat * Bsevious , *nes 1:
-bud ft
funtion (aeale */
stsuct)
oid Caest- Jist l
e(i==oatn - 14 temp)
free (temb;
-(iþsron - 1 4f-teny)
if (psey ==
NOLL)
boeah
temy temp’ net;
UAile Chead)
pointf(E biJ (%, P] ’ P1n,head ’ hunbe, haad, head ’ nsrct;
head = headnet;
else
p>next 4>not;
free lql;
int maln (
Creoc LA,5);
printf" linked dist with duli cste:n";
Quplay (tirstl;
Renove Oupli cot Ctirst);
þritt("liaked dist without dpli cet : n";
Sep3: 15, 50, 624 5,20, 58, 9l, 3, &, 37, bo, 24
i : 5, 15, 50, &2| 2058, 91, 3, 6, 31, 60, 29
Stek5:
Sep b:
3, |5 20 50 ,62158, 91,3, 8, 3 ,b0,2Y
5, 15, 20, 50581 62 91,3, 8,37, 60,24
Ditp': 5, 15,20, 50, 5%, 62,91|3,8,37,b0, 24
tepB: 3, 5,15,20,50 58 (b2,91|8 ,37, 60,24
Sp : 3, 5 8 ,5,2o ,50,58, 62., 91] 37,60,24
Se lo: 3. S $, 5, 20 31, 50o,58, 62, 91|60, 29
S : 3, 5, 8, 15, 20,31, 50 58,b0,b2, 91|24
Siepl2.: 3, 5, 8, 15, 20,24,37, 50, 58, b0, b2, 91
Selection Sort
elum
2. Repea
Dtep1: 50, 15, 62, 5, 20,58,91, 3, 8,31, 60,4 llintial lut
3, 1562 5 2o,58,91,50, B,31, 6o,24 lswap 50 and 3
Step3: 3, 5, 62,15 120,58 SI, 50, 8,37, 6o,24 |lsuoap 15 and 5
Sr 31S, 8, 15, 20,S6,9150, 6&,31, 60, 24 |l3uwa b2 and b
Jhe: 315, 8, 15,20, 58 ,91,50, 62, 37, bo,24 ||S8 s hedy in tts correct pusition
Seo. 3,5 8, (5, 20,24, 94, 50, 62 37, 60,58 |lswo 240nd 56
Se: 35,5, 15,20,24, 37,50, b2, 91, 60, 5% |lsu 87 nd 31
Steo: 3 S,$, 15,20, 24,37, So,b2, 91, b0,58 lbo alu eady n s Correct position.
Sleb: 315, 8, 15,20,24, 37, 50, 58, 91, b2, 60 ilsuwao 58 nd b2
Sheblo: 3.5,6,1S(20,24,37,So,58 b0, 91, 62 |lsusap 91 ad b2
Sle l1: 3,5,3,15,2o, 24137, 50 58 b0, b2, 91 || the lut now Sorled.
Bubble Sort
1. Stat ot the beginning gthe lat and Conpon adjacend cementa. Swapthamif
anein the torog otden.
-15,50,5, 20, 58, b2,3, 831, b0, 24, 91
end
2. Continue this broces or each pac adjacent elamedh in the list Uil the
veached. A1 this poin,the longytemed wil be at te end te the l t
- 15, 5, 20, 50,58, 3, 8,31, 24,b62,91
-5 1520 50, 58, 3, 8 37,24, 60, 62, 91
- 5 15 203, 8,37,24, 5058, bo, b2, 9)
5,15,3, 8,20,24,37, 50,58 bo, 62, 9)
3 815, 20 24, 37,
5058,bo,62, 91
peat ste 1 and2, but ony tor the fivst n-lelemnts the lest whuen
gth th lat.Jhis enures thed the lag est element sin ts ina
ositi'on.
3,5,8, I5, 20, 24,37, 50,58) 60 ,62, 91
Jhe first no de in the preordes travn sal is the root the tree. whe
na T lndex o tk root rode in the inorden trovenseu. Jhe nodes to
the root hode in the inorden traveusd reo resed theletsbtree, ond
the Yigt te root nade veprësund Hhe rgt Subtree.
Recursiu d y Cons trud the let Subtree usiy the pre orden ond inor
te nodes in the
the lyt Sotree
Recursi vey Constroct the rgt sob tree wsmg te fore ordes and in
truvcuads ttenods inte rght sulbtree.