oblov2011Сортировка методом пузырька (по возрастанию)
procedure MassivSort(var arr : array of Real; const N : Integer);var I: Integer; J: Integer; K: Integer; M: Real;begin for i:=1 to N do begin m:=Arr[i-1]; k:=i; for j:=i to n do begin if m>Arr[j-1] then begin m:=Arr[j-1]; k:=j; end; end; Arr[k-1]:=Arr[i-1]; Arr[i-1]:=m; end;end;
Сортировка по убыванию:
procedure sort; var i , j , tmp : integer; begin for i := 1 to n - 1 do for j := i + 1 to n do if a[i] < a[j] then begin tmp := a[i]; a[i] := a[j]; a[j] := tmp; end;
0 votes Thanks 0
oblov2011
procedure SelectionSort(var arr : array of Real; const N : Integer); var I : Integer; J : Integer; K : Integer; M : Real; begin for i:=1 to N do begin m:=Arr[i-1]; k:=i; for j:=i to n do begin if m>Arr[j-1] then begin m:=Arr[j-1]; k:=j; end; end; Arr[k-1]:=Arr[i-1]; Arr[i-1]:=m; end; end;
Answers & Comments
procedure MassivSort(var arr : array of Real; const N : Integer);var I: Integer; J: Integer; K: Integer; M: Real;begin for i:=1 to N do begin m:=Arr[i-1]; k:=i; for j:=i to n do begin if m>Arr[j-1] then begin m:=Arr[j-1]; k:=j; end; end; Arr[k-1]:=Arr[i-1]; Arr[i-1]:=m; end;end;
Сортировка по убыванию:
procedure sort;
var i , j , tmp : integer;
begin
for i := 1 to n - 1 do
for j := i + 1 to n do
if a[i] < a[j] then begin
tmp := a[i];
a[i] := a[j];
a[j] := tmp;
end;
var
I : Integer;
J : Integer;
K : Integer;
M : Real;
begin
for i:=1 to N do
begin
m:=Arr[i-1];
k:=i;
for j:=i to n do
begin
if m>Arr[j-1] then
begin
m:=Arr[j-1];
k:=j;
end;
end;
Arr[k-1]:=Arr[i-1];
Arr[i-1]:=m;
end;
end;