Jumat, 10 April 2009

Bubble Sort

Program Sortir dengan menggunakan Pascal :

uses crt;
var
i,j,x,temp : integer;
a : array[1..100] of integer;
label 10;
begin
clrscr;
write('Masukkan jumlah angka');
readln(x);writeln;

for i:=1 to x do
begin
write('Angka ke-',x,' = ');readln(a[i]);
end;
for i:=1 to x-1 do
begin
for j:=1 to x-i do
begin
if a[j] < a[j+1] then
begin
goto 10;
end;
temp := a[j];
a[j] := a[j+1];
a[j+1] := temp;
10:
end;
end;
writeln("Angka yang telah tersortir");writeln;
for i := 1 to x do
begin
writeln(a[i]);
end;
readln;
end.

Tidak ada komentar: