RSS
email

SelectionSort(Pascal)


{Program Pengurutan data
INSERTION SORT
Progmr: Made Agung Raharja
tgl : 231109
=--------------------------------------------------}
program Insertion_sort;

uses
wincrt;

type
Array100=array[1..100] of integer;

var
Data: Array100;
DataCount:Integer;

procedure Input(var d: Array100; var c : integer);
var
Code, k : Integer;
i : string;
begin
k:=1;
repeat
write('Masukkan angka ke-', k, ':');
readln(i);
if (i <> '') then
begin
val (i, d[k], Code);
if (Code <> 0 )then
d[k] :=0;
end;
inc(k);
until (K > 100) or (i = '');
c :=k-2;
end;

procedure swap(var a, b :integer);
var
t:integer;
begin
t:=a;
a:=b;
b:=t;
end;

procedure SelectionSort(var d:Array100; c: integer);
var
lok,i, j : integer;
begin
for i := 1 to c-1 do
begin
lok:=i;
for J:= i+1 downto 2 do
if (d[j]< d[j-1]) then swap(d[j], d[j-1]); end; end; procedure tampil(var d:Array100; c: integer); var i : integer; begin for i := 1 to c do writeln(d[i]:5); writeln; end; begin Input(data, dataCount); writeln; writeln('Sebelum Diurutkan'); Tampil(Data, DataCount); SelectionSort(Data, DataCount); writeln; writeln; writeln('Setelah Diurutkan'); Tampil(Data, DataCount); end.

Bookmark and Share

0 komentar:

Posting Komentar

 

Friends

ON-LINE