Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program shaker;
- {$APPTYPE CONSOLE}
- uses
- System.SysUtils;
- type
- TArray = array [1..16] of Integer;
- procedure Print(Arr: TArray);
- var
- i: Integer;
- begin
- for i := 1 to 16 do
- Write(Arr[i], ' ');
- Writeln;
- end;
- var
- i, low, high, current, tmp: Integer;
- //s, e, tmp, k, i: Integer;
- Arr: TArray = (0,1,2,3,4,5,7,5,9,7,9,1,4,5,8,7);
- N: Integer = 16;
- begin
- low := 1;
- high := N;
- Writeln('Non-sorted array:');
- Print(Arr);
- Writeln('--------------------');
- while low < high do
- begin
- //пузырьком перемещаем максимальный элемент вправо
- for i := low to high - 1 do
- if Arr[i] > Arr[i + 1] then
- begin
- tmp := Arr[i];
- Arr[i] := Arr[i + 1];
- Arr[i + 1] := tmp;
- current := i;
- end;
- high := current;
- Print(Arr);
- //пузырьком перемещаем минимальный влево
- for i:= high downto low + 1 do
- if Arr[i] < Arr[i - 1] then
- begin
- tmp := Arr[i];
- Arr[i] := Arr[i - 1];
- Arr[i - 1] := tmp;
- current := i;
- end;
- low := current;
- Print(Arr);
- Writeln('--------------------');
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement