Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program selection;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- const
- max = 1000;
- type
- TArray = array [1 .. max] of integer;
- var
- i, j, n: integer;
- A: TArray;
- procedure Print(var Arr: TArray);
- var
- i: Integer;
- begin
- for i := 1 to n do
- write(Arr[i], ' ');
- writeln;
- end;
- procedure SelectionSort(Arr: TArray; n: Integer); { сортировка выбором }
- var
- key, count: integer;
- begin
- for i := 1 to n do
- begin
- count := A[i];
- key := i;
- for j := i + 1 to n do
- if (A[key] > A[j]) then
- key := j;
- if (key <> i) then
- begin
- A[i] := A[key];
- A[key] := count;
- end;
- Print(A);
- end;
- write('Результирующий массив: ');
- for i := 1 to n do
- write(A[i], ' '); { вывод массива }
- end;
- { основной блок программы }
- begin
- write('Количество элементов > ');
- read(n);
- for i := 1 to n do { ввод массива }
- begin
- write(i, ' элемент > ');
- readln(A[i]);
- end;
- SelectionSort(A, n);
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement