Slide 1 Title Here

Replace these slide 1 sentences with your own featured slide descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions...

Slide 2 Title Here

Replace these slide 2 sentences with your own featured slide descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions...

Slide 3 Title Here

Replace these slide 3 sentences with your own featured slide descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions...

Slide 4 Title Here

Replace these slide 4 sentences with your own featured slide descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions...

Slide 5 Title Here

Replace these slide 5 sentences with your own featured slide descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions...

Latest Posts

Jumat, 04 November 2011

Posted by Ardhina-Widiyanto On 1:24 PM 1 komentar

Binary Search Pake Bahasa Pascal

Binary Search Pake Bahasa Pascal

binary search pake pascal, intinya cek dulu nilai terbesar dan terkecilnya lalu ambil nilai tengahnya, dan dibandingkan dengan nilai yang dicari. Apabila nilai yang dicari lebih besar dari nilai tengah maka pencarian akan dimulai dari tengah ke kanan, tapi jika lebih kecil maka pencarian dimulai dari tengah ke kiri. Nah hal ini akan mempersingkat waktu pencarian jika data tersebut bernilai berurutan. contoh 1 sampai 10 urut tidak acak..., berikut adalah sourcenya

program Binary_Search;
uses crt;

const
x = 10;

Var
arr : array [1..x] of integer;
i, kiri,tengah,kanan,cari :integer;
ketemu :boolean;

Begin
clrscr;
writeln('List Angka : ');
for i := 1 to x do
begin
arr[i] := i;
write(arr[i],' ');
end;
writeln;
write('Masukan data yang dicari (dgn Binary Serach) : ');
readln(cari);
kiri:=x;
kanan:=1;
ketemu:=false;
while not(ketemu) do
begin
tengah:=(kiri + kanan) div 2;
If arr[tengah]=cari then
begin
ketemu:=true;
writeln('Kunci yang di cari berada pada index ke ',tengah);
end
else if (cari < arr[tengah]) then
kiri := tengah - 1
else
kanan:= tengah+1;
if (kanan > kiri) then
begin
ketemu:=true;
writeln('Data yang Anda cari tidak ada !');
end;
end;
readln;
end.


Itu nilainya berurutan jika mau coba tidak berurutan maka pada arr[i] := i; diganti menjadi arr[i] := random(x) + 1;


Semoga bermanfaat... (^_^)