Sorting with Buble sort at Pascal
Sorting with Buble sort became famous when applied in algorithm and programming especially for informatics university students. well.. here is the code that built in Pascal language..alhamdulillah..although I coded so many error, finally it done..
program sorting_bubleSortV1;
uses crt;
const Nmaks = 100;
type arrayInt = array[1..Nmaks] of integer;
var
{u : arrayInt;}
n : integer;
{maks : integer;}
l : arrayint;
procedure bacalarik(var l : arrayInt; n : integer);
var
k : integer;
begin
for k := 1 to n do
begin
write('masukan nilai : ');
readln(l[k]);
end;
end;
procedure urutgelombang1(var l : arrayInt; n : integer);
var
i : integer;
k : integer;
temp : integer;
begin
for i := 1 to n - 1 do
for k := n DOWNTO i + 1 do
if l[k] < l[k+1] then
begin
temp := l[k];
l[k] := l[k-1];
l[k-1] := temp;
end;
end;
procedure tampillarik(var l : arrayInt; n : integer);
var
k : integer;
begin
for k := 1 to n do
begin
writeln('Nilai setelah disorting adalah : ',l[k]);
end;
end;
begin
clrscr;
write('Masukan banyak bilangan : ');
readln(n);
bacalarik(l,n);
urutgelombang1(l,n);
tampillarik(l,n);
readln;
End.
program sorting_bubleSortV1;
uses crt;
const Nmaks = 100;
type arrayInt = array[1..Nmaks] of integer;
var
{u : arrayInt;}
n : integer;
{maks : integer;}
l : arrayint;
procedure bacalarik(var l : arrayInt; n : integer);
var
k : integer;
begin
for k := 1 to n do
begin
write('masukan nilai : ');
readln(l[k]);
end;
end;
procedure urutgelombang1(var l : arrayInt; n : integer);
var
i : integer;
k : integer;
temp : integer;
begin
for i := 1 to n - 1 do
for k := n DOWNTO i + 1 do
if l[k] < l[k+1] then
begin
temp := l[k];
l[k] := l[k-1];
l[k-1] := temp;
end;
end;
procedure tampillarik(var l : arrayInt; n : integer);
var
k : integer;
begin
for k := 1 to n do
begin
writeln('Nilai setelah disorting adalah : ',l[k]);
end;
end;
begin
clrscr;
write('Masukan banyak bilangan : ');
readln(n);
bacalarik(l,n);
urutgelombang1(l,n);
tampillarik(l,n);
readln;
End.