Sorting algorithms/Stooge sort: Difference between revisions
Content deleted Content added
No edit summary |
m →{{header|REXX}}: removed the use of a literal for writing output. |
||
Line 1,481:
parse arg N . /*obtain an optional argument from C.L.*/
if N=='' | N=="," then N=19 /*Not specified? Then use the default.*/
do k=0 to N; @.k=k*2 + k*-1**k /*generate some kinda scattered numbers*/
if @.k//7==0 then @.k= -100 -k /*Multiple of 7? Then make a negative#*/
wV=max(wV, length(@.k)) /*find maximum width of values, so far.*/
end /*k*/ /* [↑] // is REXX division remainder.*/
call show 'before sort' /*show the before array elements. */
say copies('▒',
call stoogeSort 0, N /*invoke the Stooge Sort. */
call show ' after sort' /*show the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do j=0
/*──────────────────────────────────────────────────────────────────────────────────────*/
stoogeSort: procedure expose @.; parse arg i,j /*sort from I ───► J. */
Line 1,504 ⟶ 1,503:
end
return</lang>
'''output''' using the default
<pre>
element 0 before sort: -100
element 1 before sort: 1
element 2 before sort: 6
element 3 before sort: 3
element 4 before sort: 12
element 5 before sort: 5
element 6 before sort: 18
element 7 before sort: -107
element 8 before sort: 24
element 9 before sort: 9
element 10 before sort: 30
element 11 before sort: 11
element 12 before sort: 36
element 13 before sort: 13
element 14 before sort: -114
element 15 before sort: 15
element 16 before sort: 48
element 17 before sort: 17
element 18 before sort: 54
element 19 before sort: 19
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
element 0 after sort: -114
element 1 after sort: -107
element 2 after sort: -100
element 3 after sort: 1
element 4 after sort: 3
element 5 after sort: 5
element 6 after sort: 6
element 7 after sort: 9
element 8 after sort: 11
element 9 after sort: 12
element 10 after sort: 13
element 11 after sort: 15
element 12 after sort: 17
element 13 after sort: 18
element 14 after sort: 19
element 15 after sort: 24
element 16 after sort: 30
element 17 after sort: 36
element 18 after sort: 48
element 19 after sort: 54
</pre>
|