Home » » Program Binary Seacrh

Program Binary Seacrh

Written By Unknown on Sabtu, 24 November 2012 | 11.51



            Program Binary;
            Uses Wincrt;
            Type
                   Tabel= array [1..100] of integer;
            Var
                   Mhs: Tabel;
                   Idx, n, x, I, j, k : Integer;
              Procedure Table(var N: integer; var A : tabel);
            Begin
                   For i:= 1 to n do
                   Begin
                        Write (‘Nilai ke-‘,i,’ :’); readln(A[i]);
                   End;
       end;
            Procedure Binarysearch (A: Tabel; x: integer; N: integer; var idx: integer);
            Var
                   J,k : integer;
                   Found : Boolean;
            Begin
                   i := 1;
                   j:=n;
                   found:=false;
                   While ((i<=j) and (not found)) do
                   Begin
                        k := (i + j) div 2;
                        if (A[k]=x) then
                        found:= true
                        else
                        if (A[k] < x) then
                        i:= k + 1
                        else
                        if (A[k] > x) then
                        j:= k – 1;
                   end;
                        if (found) then
                        idx := k
                        else
                        write(‘MAAF, DATA TIDAK ADA ’);
            write (‘nilai’,x,’ tersebut terdapat pada indeks ke-‘,idx);
            end;
            Begin
                   Write(‘PROGRAM SEARCH INDEKS DENGAN MENGGUNAKAN BINARY SEARCH’);
            Writeln;
            Writeln;
      write (‘berapa banyak data yang diperlukann :’); readln(n);
            Table (N,Mhs);
        write (‘Masukkan nilai yang ingin dicari :’); readln(x); writeln;
            Binarysearch(Mhs,x,N,idx);
            End.
           



\
           

Share this article :

0 komentar:

Posting Komentar

Terimakasih Telah membaca artikel kami. Silahkan tinggalkan komentar anda disini.

 
Support : Dunia Matematika | Dunia Fisik dan Fiksi
Copyright © 2013. Blog Berbagi Ilmu - All Rights Reserved
Template Created by AM Published by Aeroplane
Proudly powered by Blogger