Minggu, 01 Maret 2009

Program Pascal Bubble Sort

program bubble_sort;
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 jumlah elemen array = ');readln(n);
for i:= 1 to n do
begin
write(' Masukkan elemen ke ',i,' = ');readln(a[i]);
end;
buble;
for j:= 1 to n do
writeln(a[j]);
readln;
end.

Tidak ada komentar:

Posting Komentar

Kirim Komentar Anda
(Send Your Comment)