Senin, 10 Desember 2012

insertion sort menggunakan DELPHI

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  tblint:array[1..100] of integer;

  i, datasisip, j, n: integer;



begin
  { TODO -oUser -cConsole Main : Insert code here }


  write('masukkan jumlah data: '); readln(n);

  for i:=1 to n do
  begin
    write('data[',i,'] = '); readln(tblint[i]);
  end;


  for i :=2 to n do
  begin
    datasisip:=tblint[i];

    j:= i-1;

    while (datasisip < tblint[j]) do
    begin
      tblint[j+1]:= tblint[j];
      j:=j-1;
      end;

      tblint[j+1]:= datasisip;
      end;

  writeln;
  writeln('Hasil Sortir');
  for i := 1 to n do
    write(tblint[i]:5);
    readln;

end.

Tidak ada komentar:

Posting Komentar