Answer the question
In order to leave comments, you need to log in
How to change the bubble method?
Write a variant of the bubble method that terminates if there were no permutations at the next step of the outer loop.
Where is the mistake?
const n=10;
type s = array[1..n] of integer;
var mas: s;
var i,j,t,k: integer;
begin
for i:=1 to n do mas[i]:=random(2);
for i:=1 to n do write(mas[i],' ');
writeln();
k:=0;
for i:=1 to n-1 do
begin
for j:=n-1 downto i do
if mas[j+1]<mas[j] then
begin
t:=mas[j+1];
mas[j+1]:=mas[j];
mas[j]:=t;
k:=k+1;
end;
if k=0 then break;
k:=0;
end;
for i:=1 to n do write(mas[i],' ');
end.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question