Sabtu, 26 September 2009

Selection Sort

program selection_sort;
uses wincrt;
var
data :array[1..100] of integer;
i,j,k,n,temp,indeksmin:integer;
begin
write('Masukkan banyak data = ');readln(n);
for i:=1 to n do
begin
write('Masukkan data ke ',i,' = ');readln(data[i]);
end;
for i:=1 to n do
begin
indeksmin:=i;
for j:=i+1 to n do
begin
if data[j] < data[indeksmin] then
begin
indeksmin :=j;
end;
end;
temp := data[indeksmin];
data[indeksmin] := data[i];
data[i] := temp;
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)