const
n=10;
type
massive = array [1..n] of integer;
procedure select(mas : massive);
var
i, j, k,tmp: integer;
begin
for i:=1 to n-1 do
k:=i;
tmp:=mas[i];
for j:=i+1 to n do
if (mas[j]<tmp) then
k:=j;
tmp:=mas[j];
end;
mas[k]:=mas[i];
mas[i]:=tmp;
write('Сортировка выбором:');
for i:=1 to n do
write(' ',mas[i],', ');
procedure bubble (mas : massive);
i,j,tmp:integer;
for j:=1 to n-i do
if (mas[j]>mas[j+1]) then
mas[j]:=mas[j+1];
mas[j+1]:=tmp;
write('Сортировка пузырьком:');
procedure insert(mas : massive);
i,j,k,tmp : integer;
for i:=2 to n do
j:=1;
while (tmp>mas[j]) do
j:=j+1;
for k:=i-1 downto j do
mas[k+1]:=mas[k];
mas[j]:=tmp;
write('Сортировка вставкой:');
i : integer;
a : massive;
randomize;
write('Массив:');
a[i]:=random(100);
write(a[i]:4);
writeln;
select(a);
bubble(a);
insert(a);
end.
const
n=10;
type
massive = array [1..n] of integer;
procedure select(mas : massive);
var
i, j, k,tmp: integer;
begin
for i:=1 to n-1 do
begin
k:=i;
tmp:=mas[i];
for j:=i+1 to n do
if (mas[j]<tmp) then
begin
k:=j;
tmp:=mas[j];
end;
mas[k]:=mas[i];
mas[i]:=tmp;
end;
write('Сортировка выбором:');
for i:=1 to n do
write(' ',mas[i],', ');
end;
procedure bubble (mas : massive);
var
i,j,tmp:integer;
begin
for i:=1 to n-1 do
for j:=1 to n-i do
if (mas[j]>mas[j+1]) then
begin
tmp:=mas[j];
mas[j]:=mas[j+1];
mas[j+1]:=tmp;
end;
write('Сортировка пузырьком:');
for i:=1 to n do
write(' ',mas[i],', ');
end;
procedure insert(mas : massive);
var
i,j,k,tmp : integer;
begin
for i:=2 to n do
begin
tmp:=mas[i];
j:=1;
while (tmp>mas[j]) do
j:=j+1;
for k:=i-1 downto j do
mas[k+1]:=mas[k];
mas[j]:=tmp;
end;
write('Сортировка вставкой:');
for i:=1 to n do
write(' ',mas[i],', ');
end;
var
i : integer;
a : massive;
begin
randomize;
write('Массив:');
for i:=1 to n do
begin
a[i]:=random(100);
write(a[i]:4);
end;
writeln;
select(a);
writeln;
bubble(a);
writeln;
insert(a);
end.