Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.50 KB | None | 0 0
  1. procedure SelectionSort(const N: Integer; var A: TArr);
  2. var
  3.   i, j, Min: Integer;
  4.   SwapsCounter, ComparesCounter: Integer;
  5. begin
  6.   SwapsCounter := 0;
  7.   ComparesCounter := 0;
  8.   for i := 1 to N - 1 do // Цикл S1
  9.   begin
  10.     Min := i;
  11.     for j := i + 1 to N do // Цикл S2
  12.     begin
  13.       if A[j] < A[Min] then
  14.         Min := j;
  15.       Inc(ComparesCounter, 1);
  16.     end;
  17.     Swap(A[i], A[Min]);
  18.     Inc(SwapsCounter);
  19.   end;
  20.   Write(ComparesCounter:10, ' |',  SwapsCounter:10, ' |');
  21. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement