Sorting algorithms/Cocktail sort: Difference between revisions
Content deleted Content added
Added XPL0 |
|||
Line 1,723: | Line 1,723: | ||
ary.cocktailsort! |
ary.cocktailsort! |
||
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</lang> |
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</lang> |
||
=={{header|Run BASIC}}== |
|||
<lang runbasic>for i = 1 to 100 ' fill array |
|||
a(i) = rnd(0) * 100 |
|||
next i |
|||
beg = 2 |
|||
siz = 100 |
|||
whatWay = 1 |
|||
changed = 1 |
|||
while changed |
|||
changed = 0 |
|||
FOR i = beg TO siz STEP whatWay |
|||
IF a(i-1) > a(i) THEN |
|||
hold = a(i) |
|||
a(i) = a(i-1) |
|||
a(i-1) = hold |
|||
changed = i |
|||
end if |
|||
NEXT i |
|||
siz = beg |
|||
beg = changed - whatWay |
|||
whatWay = 0 - whatWay |
|||
wend |
|||
' print result |
|||
for i = 1 to 100 |
|||
print i;" ";a(i) |
|||
next i |
|||
end</lang> |
|||
=={{header|Slate}}== |
=={{header|Slate}}== |