Unit 5
Unit 5
oNlr -5
Jngq'r,Jicrn soab
*he cqlt o\
ploced- ob +he
ri ide of pJoced o.t +he
ur,l\ !s
. Simi all .rrn s o'r &e d cct' &g oxe
"\.t.E '
&ajRe.n rr", .trnerrl eocacE P\ocg
,.thg
Firs o.Ee one e\eroenb , iEero.tsg 'Jt 'trlnrotJ'tft
OisqdrnoLqge
gebs
rr,.ir not atProPtiole -\oY 'lortg do'to'
Sotb +-tng
- '(ime com!,l.oditt o,6 .ri'tsetr'ftcrn
!.tfr
- simP\g lmP\emen&olictt.i
- E$f,;cieni -lurrr smoll diato Setsg
A\3o.rirrtrm'.)
'. Aor.led.'
nrC rr}
: Repeol rT t&'.rl {he
e'c,
S&e? 1
?
L tb .ri
I ,f
JI t{ sPac.r
-Ih
e..e o1h eyV eCrmPore
o L 1
L\ E
l!
ot ,{i{s,I Q\Qmant
.ur urrtl &ohe
5 -> BXo6, tfsE arrd uJg eGrt
o[ un s6rLa& .tomP
Sorted rrnsorted {cJuo un
SqblisE S&o'(e +hot
SubliSE,
caoeidey *["oIU ber.Y
dree
o
E
3
E
q
r IO-ghi$t
fifl-shi5u
sh,^tt 'rh ti3hb
comPole-
-> -$"roro'tt3
lo>l
hh
+ shitt
to \e6t
t\ 1 E o 6 o\
l IBSA , t
ot
1
2
q 5 \o
\5 [fl- shi$b @ * 'tgvrt P\ace
1 ohsut
\ix antslrhQ'( vqlu is E-) NS _>N o\, ' urg \W>t .r.r','tnAefQ
\n ssr!Q aSu bt tam? !q\ug
4t the \asb
o\ z \ 5
E \o 6
\
I
I f..\-'1
o r1 3 L{ S
-o- tamP
E
,l-
\o b, --)
Lt I
o{-
t \ \ C.
J
I
L;
lo 1 ct-
reptace @ un ttrrr' P\oce
5>6 -;* o sbi$ts
ri3hE
q>b -) N o shisb
0\ aSqlq -;.1e sti gt
t.emP
Sol ted \is
-.-J-1d. ro) 9- Shi SE
o\>\tts
q 5
I 6
?
\o I _--.--)
--.-)
6>2 shisb
t 5)z
5
0 I 2- ) Li
shfs
i\u\ C.
J I
1 5 -..)
E
0lL3q
It 1
\5 6 T \0 lq)z Shi 9g'
0 3\ 5
3
Td I lo
l-'-r-
tr >)- -) nO nee d .!o shi tt
Val!o-'
+he
5.5
13
lo
L\541.
FT,l-'frl
\ 5 61
LQroP
I
lq q 1i3ht'
t_ T \o l*TTTsl-61 t{>3 -) shitt
01 /-5 B 6-1 tr ernF
a
J '1 q b
o
2_ q
56 'i
5
(--..-..''-....__-) rO P
sort ed \ist r-r SOI
0l )-5 r{5
q \o >\
\o o shi tt
o I )to
arnP td\
Sor be D>t 2.
is uri s o.r te 4 t{> ) 12"
No g\i$b
S'u.L tiS b
3> lz
ol1 2) l2-
rl 5 6'1
Lt l& bemp
I
Sorted . <._-\
Sqfr.tut ungor tQJ rS
Sufr-\isb ) l ->shi st
o I a 3 q5 6 lo) r ->shtgb
1 l-{ 5 roln W q ) I -\shigb
3)r -\shi8t
bu.b 2>t -)shisb.
o I a3 \ 5 5 .r tr tn.?
Ea>5-) s hi $b
ti,D.l Sortad\Et. t 0>
Ll)5
5 )shig E
-) nyg sr-,i5f
6.6
I
inEj;
{ot[.;=oi'icn; it+)
Ptints $ t*o/o4"t aLd, l
3
.rr,u moir'C)
I
inE qtf = g,3err1\ '
frrr3ttaEt
inE n
= sizeo[(o)/ sizec5(ogo)
.
L'z: tg-/o sizeo'5(6)
@ / sizec6(u)
s,1
c
Ol23t{
arl
LJ-
\z 3t \ e
\
32 \a
n:6
g oxe -
p1\nt -) Be{ore Sol.irin3 a'rtab e\ernen\
q5
{.uno,rr'crn .z-all
o
Prinb Arr( l1 ?r\rs 8\32\rr ,6)
{o rlo $urnc.xcrr. d %,r ;tr'crn pottb
6(6 + {."'rn
ol 2, 5
insqn 25
/ $o ,.to {.unc rtr'on dn4 'r,.f-r'on
po,rE
i" ftr 3l
*,'--.t+ | I14 F
\
\uj --=-r
tJ of.+r] = .EQmP'
af[= 3\
.i.:9-
[@J."*
.leroP =atal
.fernp : J.5
j: &-\
rE
J- ril E rQfnP f5]
t_^.) i\e ( j>= o 6$ "ternP( -- af j ,] ri @
l):o 3S z5 ( =afrl
T 25< = 3\
-r \'r LrO
T
-\*\'ll. \ .^ ,i ,\
\ oii
a1r+il = atrl
attl :3\ 4::
j = l- \
o,
-) j
jernP: I
: o (.j)
"xe*p
ue.n? : ? j = ?-r j,E
36 .}ern p( o'cjl)
uJhi\e ( j>= o
b1: otl
EO T
A
s
1
gr\
Ot E-j
) 3\
I
1r uO
SemP ( = a(.il
oLj+il "o[!l :
o j : i\ J -',t u,o
of rtl: aCtl
\
aI (
I 3
-r 0 ('r& J: O
1
U
a o+\ -- a C"-l , ? \& 9-t \l
a(- : t9- ) l
Qurcn Sor b
ot a a \55
lo r5 9_ q \6 ll
\
nE l<rnor';n aS ke e lemenb
tuQ con ehooSQ one eteme
-; Bal:ic idPo -
in +he \isE
f got. co.n chooSg
'
anq g\efnenE
qg pi voE l
e t e.ne nL lq)
etJm ent \ov t r'n iddte
'YheY -bi'( s
ei E
ond etemenb J r
ong ra6dorn e\efient Sott'
&&
lnd ivide - co''q Llon t}P
alYoS,.r.rrto Su-b -q qlro
-)
NouJ ,t ,h) cfn
-3 Tou
If:rIE
r
\)
JIIA o A\erngn,-b
q11 +,e 9t
piv o\ts
+nQ Pr
P\o
e \qlathts '
Si dQ go p i+he r ula4
,l_!tr r rghts
It it equar .rco tln€.
og e\amenE
lett '
P''
L
Eqere".,vrf I
J
?os-rsfion 1 Pivot oO .2
PoYrJnts
o\2- q56
l--_
t"- l"\rl
,l
t\r \0 t
1
valu€ a-nol\"'Qr
+'.l.; P1r sg
thu;r !r\
onQ Su.burr arJ
J ons s u!arraX
Nsrneed@ AorE
Capft5 gar.,e PtoterA p\vots va\ue
{.rdfn o'ro 1l t a'PPI! SarocqPloeel^.
{roro Jro 6 1
1 t5 r6 rl
J
Prv ot'9 -T
t p'.voL : rb
f:.arr.'P\e-
o tz3L\ B 6-1
r-11
8 "rl uou 4'rnd' oJ\ e\cmQnL-
''oi a*"n' +non *vru
\o 5 q L and
1 b _^J
I
li.rl-"*'"nb ' \^,o G'o6ts
T pivou = o.Lol iend I
ii* n,n,."ent
by dlt to
s'roP '
-'r
b \Q
\ 5 c a f$s-T I
Stcl)&
P\voL ,l!
-
8 +t'aE , eqUo\ g
-1-
-1
\n cr em.Qng
eA
in Cre m ent
15q g6olt
l . Cr-,6ve gU nQtE
-1 \o : c 9_ \5 a
\
?,Yot SLcr'lf
neccb
b1=a -) \ncleroef,lt +t,e{5'till ,rnove '9o
O\:-3t4S6r I
r-l rO 1l
*
l-
P,uot S.t-or& 6t"pl l-r)=+/
L) s,r op .t" +t rl X Stap ,o (
elQmenb
s;t(orgtr ^t3,
@
\--1 St S-OP
I
-1
I
A
? q.
tr \
\5 \
I
o +)l
T sI
oj\r
IL r<
,\- --al-) Ye] + incremQnJ ereroenEl
'J f MoVe SI "-IT"S.
w .1
5
Slar&
Fl-"1-{c E
to
Q\QrnQnts
[ta]G11. move JEo oecc
\a-ft]-fiIzlLt I SbanE
urg. ge e
1( =+ -) FaUg,
Trtu 1 e
mj.r.l
TIL\^ r cnOvq tO nQ'(b
o t{
-.f("Cuf,atol)
-1
2
E
S 6-1 I
b 1 J 2 IJ lo
Storrg
L;
l< =a -) tf)ovg {.he g&o}t
a{rorrJ b$ t
,.<:a -) movg +.'S S,lowb a'trou.l b$ t
'1 5
lqI 5 \o
a 5totrtr
9 (:a I r..,o CScoP)
3o
j-o nd pr{oA)
S\toil! rjor r'alr(o {.roSS ? -+ S\r{4 ?lcca-
Q Vosd
s+ar'-t $nod 3rea tarfhan.tD g..Jaf
enat',go ^o.D ^ot Soin!
fi,r etangnt
@
e-n d
oi[L .trt ,fa)'A +l^'aft
Y\o-./ e s\l
guro? P'(ocQlA ,}. .rII tlo-
Fo\\oo +he
e\emenE)
end]
st'e[i"o'r
lw*t' s,te? ) s"')c'?
c o d.'r''
e\1 or i tt'.rn Pcnt r
f)l.).,*o*a
d =O
Fo'1 suao [f ,db 't.^,n*, oo* A ".1ou'rurboun
LItPo{ bo rrncL : $
f eT"rorl
I Gtt\L t +'
4{ Ug-
S.JE
3
u)hi\q ( o.fend) YPivob)
fend --l
\
( A.lor& ( end )
"t
*
r-*( olst*''ti, o ge^d'J)'
("lp 3
q
{r.t t o.f r
qf e' A] ) ; $ertan €-nd l
@
Q,^teh,soru[ h.lb r rr\o)
fl
*t Ltrb < ub)
f.f,oc ( a t tb I ub)''
= bor.bticrn
Quicnso",u ( c, 'rb, 'Loc-r) '
Quicxsort (61,Ioc1l , "P) ,
Y
!
c$ o-theY Eccomptg
o ra3 q 5 6.1
f.-1 T. s 5 r,
\
pi vot
fr gtoJl.E
p\{ot -- +
r PivoE
1St cornPorlQ
s&
r o(! jncrerne^l-eJ t f
-l(= t .r.-o- ->
60
2 (--1 )
b,
r<--1
(= ar Lr^a ) shif
movtn3
go].be r so 5,!r:p
-1
ot l{ 561
3 \ ( s-t af,rl I .1*: )
S bdlt end
5(=T -> shi sE
6 5 15 t (=a + shi gb
tr< =1 shi w
St-qt
S+arb", *4,
FI na
S"J4 en d, Y\vor;)
\3 L I 6- lil-T 8
*1,
J*t^4h"-r1 P ivrr
t-
3 7q te',
lL''o-'
@
Q.,ricn. go'rE
*t includg (sudio.h)
/f nrirr.ttng o'yrob trst codg
voi& ?vinEnrrog (inU {(eiya$r inE
f ")
gor(,.drt .i.=o. .i.<n
;,i++)
Print$(.,o/od.,r,
brinUg(s 1r,,,,1 .
j
llth cR soY
void. e E( ioL $ireu , int losc)
f
ln..E orJ P,
t( otb )
oruCJ) .Imp .,
=
Qtuck.g65 (_"xr,,.tr.ir^rf j_,);
,
(,(*uchsq u (orr,
i+ r, Jo.bb) ;
33
voiAmqinc )
f
in"r N\[o) , i' n,
prinL3 (" Entur .ro. crb . etements S:\o " ) ;
Scqn I [,,o/o&,,, 6.);
prints S (.'
E*.rr +h,e etemenLg :\n");
{or (,i: o; .i< n ', 'i + +)
f
Scon5 (" olrJ" ", d.rrrorS C.il ) ;
3
prinu.S(" rJnSof .led, elemertE S: \.") r.
fttnU er.rog loxrog , n) .,
3
@
OulPql, '. -)
5
EnEerr -$ne eLemenb8 i
It
e3
55
r5
t1
unsq&c{ eteroenL8:
rt 2,8 69 15 11
Sov,led tis& ot-rerr Qujch Sorts
I
ll l5 \'1 13 s5
ol ,- tl
F"l
3_
t tr
t a3 5s l5
ol o
voidr (lrricRSorE ( inL iYsb b)
I
f inb.i o
tT
r
)) pivot ,dirsts
) '"|.o.bL
ue-
Pr
rt
j
;ile--oaqn
.|,.r.^o
rl )
ulhl\Q (qrrLO< : arr fol d6,j< Ll (^)hi\g ( o:ofil ( -- o:utd dd I
l\ I :. tl
6d@ 23( = rt
Fa.Ir) g
T .T
\Yu.o
J 3o ,fo trrhil \oo p
.r-.rtt_r
:o+\,
\
@
urhl\g ( or,lr f4I Y oxn tPi'oc'))
-fr !ro-
t
j--
l'1 >
J-r l
Il -> T.rLq-
@ pivot-
^3u
r)
o r,\ \e I "r,r[af>ar:.fPivoE
59> rt @ olt-3t{
\r u.e_
J:l tt l5
(t<o) * rtr iE
FolLg
EOrn = |l
,trn! -- orut[O]
\LmP : tt
oxr[ol;, a*r f o]
arr lol : tl
arr fol =l\
J
Q*cksoru( alr) 9rJ\ -l )
Ir 2? 5
@
Hee p Sorb
I
Hea P *t .rr *he clee boted doro' S''ktuct-ule'
&&$pcbq6 Ho.t, (
xat tleop
1-1;6 Hoep
each o o
u.rt
3Er
chitd no
rllc-corUq, .ro
nob ho.rrr-rr
penenh. . 3
t
6 LO
w
5o
ot2
-10 bo qo q5
55 t
5o 31 rb ,to I 35
J
agoth@ n comPonq
rrri-th porrenE. .
Por,to.n
-J ccrmFo.rg 5o > (ro
tlor.r Conno& ,ri'S qn& *hQ- !lo
e\emerit .h +t'tg '(ooE, On\s Str.np {t.e
ura- oor\ !rn's alt .iE jr: .taot &po8ulrcrn
node. .
?o
f h:
h+t; qtue rrronb.b \l!l\c.reo'xQr, thgsize
Rfnl:Vafuo.
[:::1. i'uoqtA 'r,o ar \o5t Flqce
Il ",Ltmt o7 ,TT*
,to -{hc- Pe}ro^l volu.Q
pa,enr
= /"]
fc
,l attar , *o.f c.rlatel *he P
orrort volu.Q- r ura-
eof$Fo'Jlg olenL c\eroen ond.
rl
Faf^g
3
Jtebur
3
Horl {hg tt* &.)rca.'.+
o nt scteJlEeA "{he
Tou cron
gn ,
\0o ts node -t\ qb .rA c (,n &tt
"rttl-g
o1a 3 \ 56 18
5.22
c& {+,e p\acg crb fU rn. tooE No L &.tabeA r ond lr/ou uro-
o 123 56
q5 l5 a5 rq 12 I
he a P S
al .itt!-d 11"9 rulQ Fto
h e ch H a t
-> n &* delott'cn, check LoY J
eotrtPort e .rrill"
rsb
-> .Ioob
node .ui{n ilS
parenE ) chilJ'
s
s ) IO
isgreoEer
)
urhbh ooQ rPittt
loc"** "ode
zi 3\ tz]
cotoP crrr e fo lcs Tg\ rr
check r45 < lo o I r{5 61
!61 ilqaleY Fq,t^e
SertCgsrto ) soop (ror uS)
( "6;"r l?esurt )
:>
frol ,z)
l{5 ?3 Bs t9
l,.l c5 t{, to
ol 131t5 7
ot 2 3 r{5 6 +
s,
&
l5
E @ E! q
EIEE r5
o 3 2-
\
NeeE rS ( dllot'cnrr rt.+tod) 'e"ure*
ho.rr!
,9P
steP\:) +hir
qnd urhieh
eterneob rS
FlacQ hexe irsteqd
%lE, /rla pq-t-
Jo.r,F etemenb in
+q-a-o.
5. z\
steP 2
A t
I a,euted e.ternenb PJa{od herre
rsl ro l-rJ9 3o
ra3 t{ 5
Etr en eqch de,laHJ, $otturqrl& 63 chech Jdre 'l'vuo-
l
s&eP3
A
3 t{
-) Coro Poxe l5) 1
1fi.rl-
(rvo c.lnnX e)
NerE
@ c.ro"^rA .trc dclote 2^droor
noile
ho^rin .tL
3.)e,o&ax
Jcxl f,n( 3
S'rop( f 1rS)
,
a 3 I \ 5
q 9 f &o 3o I
-r>
I -r eolas s*op C q, +)
5 .2s
q 1r 'a
I a
rS
trl 5
q
3o
r5 LO 3o
i
I 23 rt 5
NQxtO woLltd Jra- &l.l.te&
o f"
q rs
120
3o
r1 \5
t,g car\ ve&rce 459 ,ti6Q Com ,to
o(
") -> 3o
H eaf |te{hod.
I s6
Ffl 1,. *F"
3
U"tQt l'\etho
GN t-s
q eheck the Aegc en
in3 a^S chi\delrrrenbs
Y s5 ho^r r9o
+he Non^Jlot +Vti," ,L 'rls % t\or
-) ehQcJR
nool g dhiefi one hcr're 8o, to111 1 | Joo{ oods
.rn
I oyr
b"t S Hqrcheq P
h eaf *b{ HE .th od onlg
Lo:5er,& lnAet' 3 .
afP .TiQ d
,b."r n m & % h o d e.
-) Slort oPP\ Jchg
.to
Jltt {rrrn
go.rn \hroJ\, e:nal
he Ae&\od {trcnn
RfBh+ +o
3\nderc-
5.2.5
n --?
["t"]+\-to+
La"Ett\ ton
B+t .kD + q5g *
qba -+ &"t nodlo \ l-1 1o 3o
oyte
ourl
Suppose r l! ruon'3- &o add one mo{q e\ernenb "h
binouS ,fsl&-l-
I
L- .'o t
q+\
Sto I
oriSinel {oros
t23t+56"
i l-1 rol 3o
L
t{ q L 1
e
t Re\h S,larGQd tt* t/4, :r
le.
-
1.!D : 3
rmv€- to,rond, .t-atf {. dn"e.xornen-b
-
froce,lA)
ande* :1 .=; nlg
inAer =6 +(n1*-r)
5.*
r5
J rsEopv\5 $g
Y€at;t$ Retho+
1- 20
5 ) f.tqa.Y,esP
t0 P otents cornPo;^e urith ohild
t t ,) .r,$ nob ->Suo+
51 ponenE ) chi\ &
\
2o)ro ->No NeeAto€ry,sdof
S(trG?
f r">1oL) gar.te -)
\-\
L3 5g
1-1 lo
,rodeek'
ti .iP
a
.tI
M
1
"".d
T
) "n(te {
a
r-3 5(+
\
3o f
t.l*
t
.!--5
2o t1 0^o \ 5 lo \5
Lr.*i",3 *tsod ttt^"
eo.n 'H.orcrreo p
5 .2"
"l
t{
t, Stcp I
.!,1 .}obts
,^:o Y c\ Ahe a
"t ta \5 6 ptaeod
\5 rt ao \ Illro iao l oh
fta}f
lo
t2 5 C S.tQPtl
r 2 3 qs 6+
1 5 P"l3q
@r-
S,Iep9
t2-3\ e6
I
Moc eq oPQrtg
a eheeR &'ls-a- s'Ea)'*ti{ 'the
\ L3\ Eg'1
S.reP 6
t 13 56
pt
sbep'i- 8
Sd,EP
t1 3 s6:l t 13 56
t
I I
5 lo \s l-t 20 3o
I
S.rep q
\13 5 b+
€e
oode
-"H".,, f,t:;:"$e.c db r.dr'
-,,@b
f .t
G,r Iongo,t cv.J A
,$.ndl our &$
G.t. ,. t&-x.i) l .dr\nA otrr
righJC cV,lt\I
dnb Y (sx;1t t ' ->
uhl[e ( J-( n dd a1,q ., nf.wtXeeul) checre{he
r^rith
---- nod€
rooc
t ,utt sh,\I
.\arSest =!'
3
r.,rhi\e ( illn td nfrJ ) qLJonB esJ)
checx. {hq
f rtorrXeeb ;,;t chi\d' uri+r roor
no/e
= ut )
t
*6(.r*,$obI=i)
f
sro{ ef.sngu.tl , nf i:) '
l"\ox Leopi\,.5 ( c
r. , .ronXel*) )
1I
J3
heop sob Lo ,
")
f
{or ['i =nla. ', i>=r ; J-- ) t\o* heoP
-) GC'IA'
f
Hoq1 heot *b{ R,n,i) '
!
tc.rL;=nl i)zf ;u:--)
f
sr.n t stq r s(if) '
v
(9
Heop *61 :->
_....-
.i=o r la-\ l
r5-,
- He"?"tt \rI),, e! Jrecurl EiOn e
SolE
s&Q? 3 '. PetScrrrn \eaP
L> R"r*ug -lt,e rnaccimuro e .!em ol.t rrir eoen eLeP
t \.e r..o.re i!an *bD *he e^d Postuor\ a^d'rgmo e
dlJl
reroqin.inl S o.n d. ,franx{ottrt
elcmanJ< ib
.rh,f" o. maL-hea.+.
@
sal;t$ the
RePeot the sceP trnGirt *c.
$,!epq:iR#..
!,{oPai&LJ of h"o.? sotE
gort:->
TmP\emeo&ofion cL He"f
l# inc\ude{s'r&o'h)
g,rof 'lhe Posiltcrrr
volA 8 -"p (o.ru tq, jnb *b ) Func.ticrrt &o
er6 ,trl}o e\emQntsS
f
inU ,remp = *o;
rtq = *b]
*b :,femP ,
j
gu,lb&.neg toodea
a ur*h nod9 ..r
l1 ro r,ea1.r$5
cn i,t orr 'tnde:c in err CJ
ll ,rlY,f
It n + st"e 06 hea?
i)
Voi& heop\3 (;.r **cf , & Nt "n*
fl
j6t Jontes&: i'.,
torqe)i {bar.'
.rirt .ntr{, -(a"i)* t; 1t gt" ch\\& "D Y "r ooE
;5 righ t. = [s-x.i)+l) a''
_\
quc < N d$ ou['r qu.l >
**[ 'ranXusJJ
"t( -t
{j,}'riSr chilA
-fouqertf: ,!eur
,Iangen +ho
a,13e.ab
> a:ufrar3 e^bf ) "t
*s( ri3vrt 1N 66 a;utf'ri ShEl
JorrXes.i '= "t1'3t\ E.,
*t (**xer!)= i)
f g*^e(d ar,rt.if , do:'n('ra'3t"E]) ',
orurL)' *t N)
Voio\ heopsorts[G'r
I
i--)
{or(.i* .i =Nl&-r I i):
o)
heap*51(-ut,ru,i)',
i
{or ( ri,f .i = N-\ ', i): o', --)
f
( doilLof , dorr:r t"if);
S.rro?
heop.i\g Lor,rl , .ir j
")
i3
void. PriniQtros [ .r,t oxnt1, i"t N)
j++)
15*,,-* 'i:o; i<N" h
|rint€ [
pr intg ["\nx
3
.rh.E c)
f !o 3
,J{$. f1 1t01
1
oulPu-E
l5Iol5t1 zo 3o
5.3q
Mer Sorb
@
t1 gsorb fsor.tin3
rlechnique]
*) div;de - conqt^qr Eechnigue
-> divfde 4hg gug\igE ep &o one e\emenb ond mersq
SorLed sq$tisE .
t3b SucP
-) divrding +he tiSE inbo strbtisE
2"d stseF-) HeySinS og +hosg sublGb to one comp\eLq SorEed.
risb -
o\ 23 q5
r5 5 2q
6 1B
8 I 3 l6 ,:_110
cq eEmenb) -) Sorb ib in or, cen Jjn
lst- step -; div,dg .thr\ .lirE &e9
egt.ol
FJnd oub Hfd o'c}
c
"trat,
5 9.q
r6
20
2 3
C'l:
t-S&p
o+ 5 61 8
v& 3 IL lo 20
= t'5
Dividg o\% . 8
\ 3 lg lo 20
l6 E 8 3 t5 to b
5
*.* gubrist iS hevtn3 o^tj oyre element:
t
.16 (-ou<up)
t
5'38
mid:(lu+ud7* ,B lb ub
me'g esorb( i
N o,8)
mclgesorE (e ,lb, 'nid)'
mer$eEoYE( f,r mid+ r, rrb)
3
;
r
rnerge ( o , ,{)
Sat t
roergesort(5,9)
--rl,rnerge(o,
:1,
\ , g)
I
m9(o,o) hs(r,,) rnPrge (o,o ,')
r.'s( oI 8)
\ ,
q(firl r-L
J .s(
\y
err) ,r.S(1'?,8 )
.ns ( s, S) ms ( tr6)
^ ,,x? ( f,r fr(
66,q rns(r,<)
5 ros ( t,' )
rrrSto ro)
e to cner$ E
con ,ho\ $
5llB n9(2ra) ) mer3 e(U,2) > -s(t,u )
rrevi€ (o 1o1r )
ldw I :q
m3(3r3 )
J
r5 2q a rb lo 20
r5 5 2t{ I I 3 lt, lo 10
\5 I ro 20
2q I
t6 3
I 8
3<L t5 rq
r5 s IL ,6
2o
5(a\ 5l r5 EE
trl t6
)
-trtta. I
s,l u{f
@ 2o
to
Zo
r6
s<8 I
u)\ichohe-
I8 rs 2\ 5
l\n
-tt
lF:- r.a
&r('8r
t/f I ao
tk
@
t5 2l{ 8 I 3 [ tu- to 20
r5 S 2cl I \ 3 rt lo 2o
I
lo 20
t5 tEl' J
2\ 8 \
j,t
I
rr,/.+ ; -6
16
os.it
Itna.uc
r5 E c -*\"/
5 cornp 2q lo
\rhich
ong zq r5 2\ ,r r6
\ 5 comP ,0
is t a r5 2l
P
.F;{ ji I6 corrp 20
\
5 8
r5
r"rge(n
f: ol7. 3 q s618
2tl
u' -[b; E. 2o
I B
i=mid *r )
kr -cb )
uhi\e [.i< =miAdSj<=ub )
d 1iy-rr) [
1cornp3
8"i6q
oc.: (: acjl) $ comp 3
@hile I j < = t^b
5 comp lO
P
oC'il ; I eomP lO t .,
btFlt = ggrcl: aCj
ti++, l5 (orlP tro
,,j
t5 co?nP irt; t<t
1 '6
e\se zq co.p16 e!e
fbtKJ --
_. l
qLJ 2\ cot\P 20 fl
t;rtil€ t.i -id)
)
j++', Y ?r''a;ni
nJ
f
b1x3: a il
)
k++'
3 l(++'
t
6.3+
Ho"3e.8oru
conluen olSorithrn '
Her3e Sovu ig a oiv(& orrd.
-> of .h$o ho,lve,r, .ort bsd6
+he ot'
- T,F d.ivideg "'lPut
mer$e8 +he
t$( +he ,llro hoNes , and tlnen 'i:b
&(})o 80r&ed ho\veg'
Alqot i4hro
f'ilL*
:::l:,:ff.:: n\erte -['urrc&fan"*''rvishts 1rnid' Voxiobre
Eu,o hqJrreg :
T Tqrn
..Jd
lf inc\rrdetsbdfo'h>
a'(l atJ'
.flrq .,..iJi
lf inclqde (conio'h) PtS"" a
ro | 'rnt
rr'i$h.F",de:t
Y
, .rir t | ;inb
void mer8e(inu orutll .!- )
fintso,i,l<l
inc n':m-.Q
int n&:lr-rrr
r,I lli"x-?il:iTil,lt t'-'-'"'"'J .'.-,
"hu ufntl r
R[..r] ., ll creote ternp orrots
,l cops r)fie dalo. 10 &cmp *ot s L-f:tJ
.$<x [.r:o ', .i < .td ', it +)
Lf.i) = o:utf -o+il '
*.xCi=o ) i<"ai jt+)
rl
RtSl = ".r,x f rn+
I
=o) i=o I
r.i l
L u l
LL
j
abe
I
ourfxl = RCj)'
j++ 1
3
k++ )
l Ltl , i{ +hsrQ- * *U
coP$ J(he ^remo.ll1dnl streroe11Jcs ctb
il
5. 3q
qrhite[!i<nl')
f
otutLt(l: LL\il ;
.i.+ + ',
t(++
l
3
/l coPb -tl'e vemor.,rh3 g\ements o'b RLl ,.r{ tturrs' ort9- an$
urhileCj< nr)
[email protected]
= RLSI;
j+r ,
t(+{ l
iI
void. mer3e Soru ( .rirr &rutl-1 ,i"&,';trr)
f
*{( l<r)
t,.,, *:9tCr-')'&)
rnerte SorbIa'r<t 3' tm)J
metXe SorE(ar*, m+r r Y),
rnettg ( ary .-[1 m 1.r),
,
3
j
voiA printfl^''r"X Ii''r nCl ' i'c size )
(c
t J\! &
.,i,lc rno,inC)
f
inb atrfl = f ,",r, rr3 1516141
inE qr.r siz€ = sizec6C-,") [ Sizeo((exr1o:) .
)
p.rirr,tS(tr G.iven o:tro5.rl, \nt,) ]
F.*dry(+
"-,-size )
prinh. h.rr..qJ crrur , ',
I
menge8orE(arul r o, oururr_eiz€ -l ) .
priots g( " \n So'..be& ar"rot\ ,, \r,,,),
Prius ( or.lr , orur-eiz.e )
T eturn O',
3
ou.Lpu-ts
Griv en o:t:t
tz tl l3 6z
So .Ll
5
5. \l
sl
ctr
s {
I
T I
EI (tlC{ >{
c'
L:I s s
l, oJ d- qf
3dE n n
\J
n
t-) 9 ? C,
c\.
o
i"fl o o o o o o
=J,,
--t-----F-
o
eJ
I o,
,E
't
c cl
ct c c
I
co
oE
o)
o) ( g)
gr c{
! o c c Ic
o, u
c tsb U
o o
g
s !
(f,
+o o
o o \, A-
5
o o +
IJ
c
o
U p J
a)
7
E
g
,l
{,J
o
8
J!-
E
t' c ?O't c ?C) o,
3 c{
3 U 6) c.l cr) :<
E oi) o
4 c 9 3 o o ol
0 o
c c a
t
,<
U q,
o \-, c c cl
o o o o o
C"
d I
o E
c.l
E q) ,+
{
t t-
I Ed c c Gq) ,
!
F
€
-!)
d)
n
.-)
rl ? 9
d)
c
6r)
o o c
o
t
9
ll
d
ca
oJ
o o o o
c
o
c
o ?
6
,6,
>ol
to I t,
3
-r'1 I
c
c
) Io ) !
o
.b
o -tJ I ct t
a IJ
{ -b b 6:l
o)
4 g
q/ 6 { .a o
-o-
C
E
-s
-F
't q,i
1, (J
_9(
{ o
o b , \ J ci(J
U o
(,.) d 6 5 o \ :.
o
o/ OJ { al
€ a :
co
c
H & -+. {
F -t
5'tlL
B;oorl Aeareh
j S 61 sq h:lo
ot 2
\5 eq 63
5 l1 23 25
\tt
,rtr
.9
mid
L
,.!+'r
o
l $ \oo 1
f/
tl 5
dtrur.li mr
b B6
: Lo+q/s]
9/g = u'5
\q
ld'
ca>e r. ' lllr-,n:
t*= -;o16..
ea.LQa: ..-
J"s b ?r' t!' f+l
dtft? ovt€ l agmidJ
.1. \
c
t{ --) 3 cole ca,be3:
o doro)a. dl
doto = 5q 59: aful, Crn'
+
5 sq< sg:: 29 iro
qtql
5 5c) otq)
5 9<qE MO
5 1)zs €.h-qturqoO
(, ("
L go $gnE 5e) -o,toB
J 51
drtbidQx- a 5
e6rn FoJre <i3trt \nde:c l\
51
=c. trl
5g 6-3, N6
olgorithm 5q (6a B e-5
L) gq ss6tr
(a"ro 1 ofrnid' l)
.i^E B.in ou5Seoxchr ( o,.,, aoto)
f e.rr,e.r{
{ =rnid-\ )
.IzO r ^C= n-\ ,
eI:,e
r-,rhi\e ( O<*) ..9- =rnfd{ \
'
f )
mid. = \
!_, le$) : \etLur{\ -\
u{ [ doro == et"id"]) 3
rebu'\n mid' "
5.\3
i-\
B.i"roJ.t SeoYtch e\go'ri+hrn
C P{o1.(arfl
i,.rg rrroirt C )
f arrJr?[a,sr\r\o "^ot ,,
'rnE
i$E ,r - gizecf,
(orr) f eize('6
n-\ r
9c );
, : :;:' binonr58":.':
--
.t# G no$ PsrlAQnl
( g.esurJt = =-t) I Piinrrt"
'P"*g[,. E
i), P&LD.Qrt& a'E-
.r, or'ro'r5) '
o/od' t' "reeuLb )
.'.+e.^- ,
"
1g-ttrnn O',
)
oulPu-b
or j,ndex' 3
EJ-offtcntr 'A PreiSe,r"b
9't{5
Luiteon geostoYr
inE seone\.
f
int o',
{or(.i=o ', j,(. st 'r 'i++)
.{ totrf'.tJ --= cc)
'feEu}(n rl'
'r eE u'lrr -\ '
\
5- q6
inc mqinc)
t
inE orlLJ = { zr3rrarlo,u,o}
inr rc = \o '
inE N -- size orbco{{) | sizec5 fax'rEol)'
inE .result = Seortchf anr , Nr*)
.r! no.r. PrQAenb ln
[reeult =-r) ? prirrrs(" e'trt'e"r .lr,
= o-E
P Sr-O-rtCn'=
orto.r5.' ) ! PrintsS( " GJslnenJs
,rr.dQ':n o/o J' , I ,yr-qj,,,rJ-b)',
{e.!unn o .,
3
OuEPU-b oE}n de{ 3
656,erF .$ PrL!))onis
o\a su \ro
3 u \o
*^\o
\ro
2 ==\O No sv'+b
qorn?oJ\e
a J \.\ \o tto
.i. CotnPorre, 3=:\o ruo shi'(b
\6 ho
Qoff}Polte q= 2\o No shi tb