sort.. metode pengurutan data

sort1.jpg 

program buble_sort;
uses wincrt;
type larik = array [1..100] of integer;
var jmldata: byte; data :larik;

procedure input_data ( var data: larik; jmldata:byte);
var i:integer;
begin
  writeln(‘masukkan data berupa angka’);
  for i:= 1 to jmldata do
    begin
      write (‘ data’, i,’:’);readln(data[i]);
end;
end;

procedure cetak_data( data : larik; n:byte);
var i :integer;
begin
  for I:= 1 to n do
  writeln  (‘data ‘,i,’:’,data[i]);
end;

procedure tukar ( var a,b : integer );
var temp :integer;
begin
  temp:=a;
  a:=b;
  b:=temp;
end;

procedure bubble_sort (var data: larik; jmldata:byte);
var i,j:integer;
begin
  for i:= 1 to jmldata-1 do
   for j:= i+1 to jmldata do
    if data[i] > data[j] then tukar (data[i],data[j]);
end;
begin
 write (‘jumlah datanya :’);readln(jmldata);
 input_data(data,jmldata);
 writeln(‘data sebelum diurutkan ‘);
 cetak_data(data,jmldata);
 bubble_sort(data,jmldata);
 writeln(‘data setelah di urutkan ‘);
 cetak_data(data,jmldata);
 end.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s