Sorting algorithms/Cocktail sort with shifting bounds: Difference between revisions
Sorting algorithms/Cocktail sort with shifting bounds (view source)
Revision as of 13:20, 27 July 2020
, 3 years ago→{{header|ALGOL 60}}: better
m (Swift - use camel case) |
PatGarrett (talk | contribs) (→{{header|ALGOL 60}}: better) |
||
Line 179:
{{works with|A60}}
<lang algol60>begin
comment Sorting algorithms/Cocktail sort with shifting bounds - Algol 60;
nA:=20;
procedure cocktailsort(lb,ub);▼
value lb,ub; integer lb,ub;▼
begin
integer
boolean swapped;▼
begin
lbx:=lb; ubx:=ub-1; swapped
for i:=1 while swapped
A[i] :=A[i+1];▼
A[i+1]:=temp;▼
swapped:=true▼
end swap;▼
begin
integer temp;
temp :=A[i];
▲ A[i] :=A[i+1];
▲ A[i+1]:=temp;
▲ swapped:=true
▲ end swap;
for i:=lbx step 1 until ubx do if A[i]>A[i+1] then swap(i);
if swapped
then begin
for i:=ubx step -1 until lbx do if A[i]>A[i+1] then swap(i);
ubx:=ubx-1; lbx:=lbx+1
end
end
end cocktailsort;
begin▼
for i:=lb step 1 until ub do A[i]:=entier(rand*100)▼
integer i;▼
end inittable;
▲ for i:=lb step 1 until ub do A[i]:=entier(rand*100)
▲ integer i;
▲ begin
for i:=lb step 1 until ub do outinteger(1,A[i]);
▲ integer i;
nA:=20;
inittable(1,nA
▲ writetable(1,nA)
end </lang>
{{out}}
|