Question: cocktail sort

Question:cocktail sort

Jabz 433 Maple

Hi merry xmas and a happy new every1.

I am trying to code the cocktail sort algorithm into maple but having some difficulties.

i coded bubble sort but cnt seem to code the cocktail sort any help would be appricited.

 

restart:
l:=[5,4,3,2,1]:
for j from 1 to nops(l)-1 do:
for i from 1 to nops(l)-1 do:
if l[i] > l[i+1] then
d:=l[i]:
l[i]:=l[i+1]:
l[i+1]:=d:
fi:od:od:
print(l);
 

The above is 'bubbling' up the list how do i get smaller numbers to 'bubble' down the list?

Please Wait...