Skip to content

Unit Search

September 23, 2008

unit search;

interface

uses crt;
type larik = array [1..100] of integer;
var
i,n, y : byte;
x : integer;
l : larik;
found: boolean;

procedure sequential (var l : larik; x : integer; n:byte);
procedure binary (var l : larik;x: integer; n:byte);

implementation

procedure sequential (var l : larik; x : integer; n:byte);
begin
i:=1;
found := false;
while (not found) and (i<=n) do
begin
if x=l[i] then
found := true
else
i := i +1;
end;
clrscr;
if found then
writeln(‘Elemen yang bernilai ‘,x,’ berada pada index ke ‘,i)
else
writeln(‘Elemen yang bernilai ‘,x,’ tidak ada pada semua index’);
writeln(‘===========================’);
writeln(‘ Index ke- Nilai Data’);
writeln(‘—————————‘);
y := 5;
for i := 1 to n do
begin
gotoxy(6,y);
writeln(i);
gotoxy(21,y);
writeln(l[i]);
inc(y);
end;
writeln(‘===========================’);
end;

procedure binary (var l : larik; x :integer; n:byte);

var
a,iA,iAk,iT : byte;
kondisi : char;
temp : integer;
j : byte;
begin
{prosedur mengurutkan data}
{—————————————}
for i := 1 to (n-1) do
for j := n downto (i+1) do
if l[j] < l[(j-1)] then
begin
temp := l[j];
l[j] := l[(j-1)];
l[(j-1)] := temp;
end;
{—————————————}
a:=0;
iA :=1;
iAk :=n;
found :=false;
while ( not found) and (iA<=iAk) do
begin
iT:=(iA+iAk) div 2;
inc(a);
writeln(‘Iterasi ke ‘,a);
writeln(‘iA = ‘,iA);

Unit di atas adalah unit yang berisi prosedur – prosedur searching data. Yaitu prosedur binary dan sequential. Download di sini untuk source code dan file *.TPU nya.

Untuk memanggil Unit tersebut maka diperlukan sebuah program.

Program searching;
uses crt,search;
var
option : char;

begin
clrscr;
write(‘Masukkan banyak data : ‘);
readln(n);

Download source code nya di sini.

Komen yaw…

2 Comments
  1. wisnu permalink

    cara gabungin supaya bs di compile gmn??

  2. simpan unit nya di folder TPU, trus compile source code yg 2 itu.. (program pemanggilnya)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: