unit 5 pps
unit 5 pps
4 G
AvYay tound
I/p
key
Seorehig (or)
Not found
)NEAR SEARH :
23 4
Key: 51ey
int Ale], key,!
tor(i=o;i<io;i*+)
it (a(] =z key)?
break;
seanf (d , key);
tov (fwo;ic t;i+){
breát;
ow
high
wigh id 1
mid
2 334'6
4
32 A(id]
46
vey
) 45
hioh rd-1
high 3)< 14 *
32 > 14
3) =A2]
step nid = 2 -a 20
=3
high 32 P 20x
Step4
Srep4
Sn case of e 31 =key
loo -3
bigh3 check
mid = 3+3 -3 Step 4
low-3
TRUE
high:3
id =3+3 3
(ser} 31 =- Al3]
incwde <staio.h >
int main C{
int Alo), (ow=0, high 4, key: mid ;
toy (iso; icio;i+){
priott('FoIND),;
break rey 48)
else oo =md + 1,
48 -AJx
48 ==Ak]
48==A* 46
(aa)
48c 46Y
low=& ohile
sort bubble wing anay kovted pvntt
i"
n)bubblesort
;(arr,
(otoJ) (av)/kine
of oftiee n= nt
qo} 25
,li,,/2,22 =b4,34, nra
c)i man int
('n"); pritt
awti); (vd;!priatt
icn;it( iz0j (int for
,ntn)t pintaway
on(int void
tenpi avrlj]=
lj+]; ar anj]
amlj; temp= int
arlitJ arljJ> suap
Cj+): (arli
a> t
;++){ n-i j<iz0) (int for
;+)5 n-t ici=0, (int tor
bubblesort
(int vojd
t
)í arC],
stdion> fnctude
< t
SORT
# BUBBAE t
# SeLec+iDN SDRTING
AhGORITHM
) Stast wth the -fst elemenr in the asay
>) Iterate the array to fnd the smalest element
-hvough
) Suoap the smallest element wh fvst element
4 move O-The
Ttho net poiaon and vepeat steps Tuo and 3
tor Yenaning elemens
# ncude cstdio h
Vod seleotonSort ( int ar [J, inti
in i minlda,temp ;
for (izo:ien;i++)1
V Fnd the mis element n rem ain ing asay
milda i;
anlauintda];
aY minld] a ;
arY[iT temp
41 44 Passt
R
5/49
Pas2
element Smallust
valu
-1,1. inden
,
-s
4
+)
o); (arh,
Pvnthrvay
aray:) Sovted pròtt
/"
(avp, SortSelecton
(ar,n Arva print
:); aray ("ovina printt
(arto]) ; size tar)/
ot oftize = nint
2 , 12, 25,
", anC]j6u, int
()
mar tnt
l"yo; pviatt
(J);: arr "d" prutt
Pas4
/-3
Pass
Pass
&
4| S 4|9
fmalles
<3
núd index =4
3
¿=3 ’ACj]e A[mininde] 5<2
midinder i
tor (jti’n-di
minindenot
it (rininderl=)E
tenp -A[
rriov
INSeR TION SORT AL GORITHM int main C1
int awl]-in,1, 13,5, 6}
) start uth the lecond element as the key int n = ize ot (a) / ie ot (an o);
> CopaYe the key ith elemenzs befoe it. pvintt ("oniginal array :);
3) s i t all elemens reater than the key one pontion
prùthrray (an);
inserion Sovt (arr,);
the nghr.
4) Tnyert correet Dosun
the key at is
priott (" Sorted trYay );
Repeat toY alU elemens n aray.
include <itdio hs
void insertionsort ( int ang, int )i
Dnseruon SoYt
anfjl zkey:
a3
a s sy
key a
i=4 MOve a lo net
1=3,a,I,o
(ail23| 26J24/29)
lcey
a|a3|26] a>129
a1|23|36|}24[28)
J=493,2,1,0