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