Advertisement
destr0y

Lab2_1

Mar 21st, 2020
3,537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var a: array of integer := (20, 18, 7, 4, 5, 14, 6, 1, 12, 9);
  2.  
  3. procedure BubbleSort;
  4. var
  5.   flag: boolean;
  6.   x: integer;
  7. begin
  8.   for var i := 0 to a.Length - 1 do
  9.   begin
  10.     flag := true;
  11.     for var j := a.Length - 2 downto i do
  12.       if a[j] > a[j + 1] then
  13.       begin
  14.         flag := false;
  15.         x := a[j];
  16.         a[j] := a[j + 1];
  17.         a[j + 1] := x;
  18.       end;
  19.     if flag then break;
  20.   end;
  21. end;
  22.  
  23. begin
  24.   writeln(a);
  25.   BubbleSort();
  26.   writeln(a);
  27. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement