Sorting algorithms/Comb sort: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, used a reduced-sized font for the output.
(Added Rust solution)
m (→‎{{header|REXX}}: added/changed comments and whitespace, used a reduced-sized font for the output.)
Line 2,294:
=={{header|REXX}}==
<lang rexx>/*REXX program sorts and displays a stemmed array using the comb sort algorithm. */
call gen; w=length(#) /*generate the @ array elements. */
call show 'before sort' /*display the before array elements. */
say copies('▒', 60) say copies('▒', 60) /*display a separator line (a fence). */
call combSort # # /*invoke the comb sort (with # entries)*/
call show ' after sort' /*display the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
combSort: procedure expose @.; parse arg N /*N: is the number of @ elements. */
g=N N- 1 /*G: is the gap between the sort COMBs*/
do until g<=1 & done; done= 1 /*assume sort is done (so far). */
g= g * 0.8 % 1 /*equivalent to: g= trunc( g / 1.25) */
if g==0 then g= 1 /*handle case of the gap is too small. */
do j=1 until $ >= N; $= j + g /*$: /*$:a temporary tempindex index variable(pointer). */
if @.j > @.$ then do; _= @.j; @.j= @.$; @.$= _; done= 0; end
end /*j*/
end /*until*/ /* [↑] swap two elements in the array.*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: @.=; @. 1 = '----polygon--- sides' ; ; @.12 = "dodecagon 12"
@.12 = '----polygon---============== sides=======' ; ; @.13 = "tridecagon 13"
@.23 = '==============triangle ======= 3' ; @.14 = "tetradecagon 14"
@.34 = 'trianglequadrilateral 4' ; 3' ; @.15 = "pentadecagon 15"
@.45 = 'quadrilateralpentagon 4' 5' ; @.16 = "hexadecagon 16"
@.56 = 'pentagonhexagon 5 6' ; ; @.17 = "heptadecagon 17"
@.67 = 'hexagonheptagon 67' ; ; @.18 = "octadecagon 18"
@.78 = 'heptagonoctagon 7 8' ; ; @.19 = "enneadecagon 19"
@.89 = 'octagonnonagon 89' ; ; @.20 = "icosagon 20"
@.9 10 = 'nonagondecagon 910' ; ; @.21 = "hectogon 100"
@.1011 = 'decagonhendecagon 11' 10'; ; @.22 = "chiliagon 1000"
@.11 = 'hendecagon 11' ; @.23 = "myriagon 10000"
do #=1 while @.#\==''; end; #=#-1 /*find how many elements in @ */
#= return #-1; w= length(#); return /* [↑] adjust # because of the DO loop.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do k=1 for #; say right('element',15) right(k,w) arg(1)":" @.k; end; return</lang>
 
Data trivia: &nbsp; A &nbsp; ''hendecagon'' &nbsp; (also known as an &nbsp; ''undecagon''
Data trivia: &nbsp; orA &nbsp; ''unidecagonhendecagon'') &nbsp; is(also fromknown theas Greekan word&nbsp; ''undecagon'' &nbsp; or &nbsp; ''unidecagon'') &nbsp; is
from the Greek word &nbsp; ''hendeka'' &nbsp; [eleven] &nbsp; and &nbsp; ''gon─'' &nbsp; [corner]. <br>
 
{{out|output|:}}
(Shown at three-quarter size.)
<pre style="height:80ex">
 
<pre style="heightfont-size:80ex75%">
element 1 before sort: ----polygon--- sides
element 2 before sort: ============== =======