Uses Crt;
Type
Arraykoe =
Array[1..10] of Integer;
Var
A : Arraykoe;
i, j : Integer;
N1, X1, IX1 :
Integer;
Procedure CariBinarySearch(L:Arraykoe; N : Integer; Var
IX:Integer);
Var
Ia, Ib : Integer;
K :
Integer;
ketemu : Boolean;
Begin
Ia:=1;
Ib:=N;
ketemu:=false;
while (not
ketemu) and (Ia<=Ib) do
Begin
k:=(Ia+Ib)div 2;
if (L[k]=IX)
then
ketemu:=true
else
If (L[k]
< IX) then
I:=k+1
else
Ib:=k-1;
End;
If (ketemu) then
Writeln('Ketemu di :',k)
else
Writeln('Tidak Ketemu');
End;
Begin
Clrscr;
Write('Berapa
Data : ');Readln(N1);
For i:=1 to N1 do
Begin
Write('Data
ke-',i,' : ');Readln(A[i]);
end;
Write('Masukkan
Data yang dicari : ');Readln(IX1);
CariBinarySearch(A,N1,IX1);
Readln;
End.
No comments:
Post a Comment