Sorting algorithms/Cocktail sort: Difference between revisions
→version handles blanks: De-obfuscate Rexx version
(→version handles blanks: It is a Rexx idiom to use <stem>.0 to hold the number of items in numerically-suffixed stem arrays.) |
(→version handles blanks: De-obfuscate Rexx version) |
||
Line 3,658:
/* shuffle sort, shuttle sort, or */
/* a bubble sort variation. */
call
call
call cocktailSort
call
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
cocktailSort: procedure expose
nn = items.0 - 1
do until done
do j=1 for nn; jp= j+1▼
done = 1
do j = 1 for
jp = j + 1
if items.j > items.jp
temp =
items.j =
end
end /*j*/
do k = nn for nn by -1
kp = k + 1 /* Rexx doesn't allow "items.(k+1)", so use this instead. */
if items.k > items.kp then do
done = 0
temp = items.k
items.k = items.kp
items.kp = temp
end
end /*k*/
end /*until*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
genitems: procedure expose items.
items.9
items.24='the fool [often unnumbered] ◄─── XXII'
▲ @.0 =24 /* number of entries in the array. */
items.0 =24 /* number of entries in the array. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showitems: procedure expose items.
parse arg phase
width = length(items.0)
say 'element' right(j, w) arg(1)":" @.j▼
do
return /* └─────max width of any line.*/</syntaxhighlight>▼
return</syntaxhighlight>
{{out|output|text= when using the internal default inputs:}}
|