szostak.pev.pl
SORTOWANIE PRZEZ WSTAWIENIE program isort;

uses crt;

procedure InsertionSort(var tab: array of integer);

var
i, j: integer;

tab2: array [0..9] of integer;

begin

tab2[0] := tab[0];

for i := 1 to 9 do

begin

j := i - 1;

while (tab2[j] > tab[i]) do

begin

tab2[j+1] := tab2[j];

dec(j);

end;

tab2[j+1] := tab[i];

end;

for i := 0 to 9 do

tab[i] := tab2[i];

end;

procedure ShowTab(var tab: array of integer);

var

i: integer;

begin

for i := 0 to 9 do

write(tab[i], ' ');

writeln();

end;

var

i: integer;

tab: array [0..9] of integer;

begin

clrscr();

randomize();

for i := 0 to 9 do

tab[i] := random(1000);

writeln('Tablica do posortowania: ');

ShowTab(tab);

readkey();

InsertionSort(tab);

writeln('Posortowana tablica: ');

ShowTab(tab);

readkey();

end.