Sabtu, 26 September 2009

Insertion Sort

program insertion_sort;
uses wincrt;
var
i,j,k,n,sisip:integer;
data:array[1..100] of integer;
begin
clrscr;
write('Masukkan banyak data = ');readln(n);
for k:=1 to n do
begin
write('Masukkan data ke ',k,' = ');readln(data[k]);
end;
for i:=1 to n-1 do
begin
if data[i]>data[i+1] then
begin
sisip:=data[i+1];
j:=i;
while (j>=1) and (data[j]>sisip) do
begin
data[j+1]:=data[j];
data[j]:=sisip;
j:=j-1;
end;
end;
end;
writeln('Setelah diurutkan :');
for k:=1 to n do
begin
writeln(data[k]);
end;
readln;
end.

Tidak ada komentar:

Posting Komentar

Kirim Komentar Anda
(Send Your Comment)