Sorting algorithms/Strand sort: Difference between revisions

m
→‎{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~
m (→‎{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~)
Line 940:
well as allowing a pre-pended list of numbers).
<br>It can handle integers, floating point numbers, and exponentated numbers.
<lang rexx>/*REXX program uses a strand sort to sort a random list of words | nums.*/
<lang rexx>
/*REXX program uses a strand sort to sort a random list of words | nums.*/
 
parse arg size minv maxv old /*get options from command line. */
if size=='' then size=20 /*no size? Then use the default.*/
Line 949 ⟶ 947:
do j=1 for size /*generate random # list*/
old=old random(0,maxv-minv)+minv
end ?*j*/
old=space(old) /*remove any extraneous blanks. */
say center('unsorted list',length(old),"="); say old; say
Line 955 ⟶ 953:
say center('sorted list' ,length(new),"="); say new
exit
 
/*─────────────────────────────────────STRAND_SORT subroutine───────────*/
strand_sort: procedure; parse arg x; y=
Line 965 ⟶ 962:
end
return y
 
/*─────────────────────────────────────MERGE subroutine─────────────────*/
merge: procedure; parse arg a.1,a.2; p=
Line 974 ⟶ 970:
if word(a.2,w.2) <= word(a.1,1) then return space(p a.2 a.1)
#=1+(word(a.1,1) >= word(a.2,1)); p=p word(a.#,1); a.#=subword(a.#,2)
end /*forever*/
return space(p a.1 a.2)</lang>
</lang>
Output when using the input of <tt> 25 -9 30 20.5117 1e7 </tt>:
<pre style="height:20ex;overflow:scroll">