program insertion(input,output);
const
MAX = 10;
var
a : array[1..MAX] of integer;
i, n : integer;
procedure insertion_sort;
var
i, pos : integer;
value : integer;
done : boolean;
begin
for i := 2 to n do
begin
value := a[i];
pos := i;
done := false;
while not done do
begin
if pos <= 1 then
done := true
else if value >= a[pos-1] then
done := true
else
begin
a[pos] := a[pos-1];
pos := pos-1
end
end; {while}
a[pos] := value;
end {for}
end;
begin { main }
writeln('How many number would you like to sort (max=',MAX:2,') ?');
readln(n);
writeln('Enter in ',n:1,' numbers:');
for i := 1 to n do
read(a[i]);
insertion_sort;
for i := 1 to n do
write(a[i]:1,' ');
writeln
end.
const
MAX = 10;
var
a : array[1..MAX] of integer;
i, n : integer;
procedure insertion_sort;
var
i, pos : integer;
value : integer;
done : boolean;
begin
for i := 2 to n do
begin
value := a[i];
pos := i;
done := false;
while not done do
begin
if pos <= 1 then
done := true
else if value >= a[pos-1] then
done := true
else
begin
a[pos] := a[pos-1];
pos := pos-1
end
end; {while}
a[pos] := value;
end {for}
end;
begin { main }
writeln('How many number would you like to sort (max=',MAX:2,') ?');
readln(n);
writeln('Enter in ',n:1,' numbers:');
for i := 1 to n do
read(a[i]);
insertion_sort;
for i := 1 to n do
write(a[i]:1,' ');
writeln
end.
Terima Kasih Sobat Sudah:
1. Berkomentar Dengan Sopan
2. Tidak Memasukkan Link Aktif Dalam Form Komentar
3. Berkomentar Sesuai Artikel/Postingan
4. Berilah Informasi Kepada Admin Jika ada script yang Sudah tidak berfungsi
5. komentar Jorok/kasar /berbau Sara/Porno /saya anggap sebagai SPAM
Jika Sudah Mematuhi Peraturan diatas Anda Sudah dianggap SOPAN.
Thanks
EmoticonEmoticon