Bubble Sort pada Pascal


uses wincrt;
var
i,n,j : integer;
a: array [1..100] of integer;

procedure buble;
var z: integer;
begin
for i:= 1 to n-1 do
begin
for j:= n downto i+1 do
begin
if a[j] < a[j-1] then
begin
z:= a[j];
a[j]:= a[j-1];
a[j-1]:=z;
end;
end;
end;
end;
begin
write('Masukkan Banyak larik (Maks 100): '); readln(n);
for i:= 1 to n do
begin write('A[',i,'] : '); readln(a[i]);
end;

buble;
write('Data setelah diurutkan : ');

for j:=1 to n do
write (a[j],' ');
end.

Preview

buble sort

Advertisements

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