Sorting algorithms/Stooge sort: Difference between revisions

m
→‎{{header|REXX}}: placed the generating code in a subroutine, used a template for the output section, changed wording in the REXX header section.
No edit summary
m (→‎{{header|REXX}}: placed the generating code in a subroutine, used a template for the output section, changed wording in the REXX header section.)
Line 1,742:
 
=={{header|REXX}}==
This REXX example starts an array at element zero   (but any integer could be used);   a zero-
<br>zerobased index was used because the algorithm shown in the Rosetta Code task used zero.
<lang REXX>/*REXX program sorts an integer array @. [the first element starts at index zero].*/
parse arg N . /*obtain an optional argument from C.L.*/
if N=='' | N=="," then N=19 /*Not specified? Then use the default.*/
wV=0 call gen@ /*widthgenerate ofa thetype largestof scattered value,array. so far.*/
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.*/
wN=length(N) /*width of the largest element number.*/
call show 'before sort' /*show the before array elements. */
say copies('▒', wN+wV+ 50) /*show a separator line (between shows)*/
Line 1,758 ⟶ 1,753:
call show ' after sort' /*show the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen@: wV= 0; do k=0 to N; @.k= k*2 + k*-1**k; if @.k//7==0 then @.k= -100 - k
wV= max(wV, length(@.k) ); end; /*findwN=length(N); maximum width of values, so far.*/ return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do j=0 to N; say right('element',22) right(j,wN) arg(1)":" right(@.j,wV); end;return
Line 1,769 ⟶ 1,767:
end
return</lang>
'''{{out|output''' |text=&nbsp; when using the default (internal generated) inputs:
<pre>
element 0 before sort: -100