Musthopz's Site

Share Everything.

Bubble Sort Pada Pascal


program bubblesort_ascending;
uses crt;

const maks = 50;

type Larik = array[1..maks] of integer;

var n,i,j: integer;
L: larik;
min: integer;
temp: integer;
ulang: char;

{=====INPUT LARIK=====}
begin
repeat
clrscr;
writeln(‘masukkan jumlah data : ‘); readln(n);
for i := 1 to n do

begin
writeln(‘masukkan data ke-‘,i,’;’); read(L[i]);
end;

writeln(‘=============’);
writeln(‘Data inputnya adalah : ‘);
for i := 1 to n do
write(L[i],’ ‘);

{====PROSES SORTING Bubble Sort ASCENDING====}
for i := 1 to n-1 do
begin
for j := n downto i+1 do
begin
if L[j] > L[j-1] then
begin
temp:=L[j];
L[j]:=L[j-1];
L[j-1]:=temp;
end;
end;
end;

{=====TAMPIL====}
writeln;
writeln(‘Data Setelah diurutkan dengan Bubble Sort Ascending : ‘);
for i := 1 to n do
write(L[i],’ ‘);
readln;

readln;

writeln;
write(‘ulangi lagi? [y/t]: ‘);readln(ulang);
until(ulang)<>’y’;
end.

Single Post Navigation

Tinggalkan Jejak anda

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: