Sorting algorithms/Comb sort: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output.
m (→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output.)
Line 1,998:
 
=={{header|REXX}}==
Programming note: &nbsp; the REXX statement (line 12) &nbsp; &nbsp; <big> '''s=trunc(s*0.8)''' </big> &nbsp; &nbsp; could've been expressed as: &nbsp; &nbsp; <big> '''s=s*0.8%1''' </big> &nbsp; &nbsp; (which is faster), but is more cryptic.
<lang rexx>/*REXX program sorts and displays a stemmed array using the comb sort algorithm. */
call gen; w=length(#) /*generate the @ array elements. */
Line 2,008 ⟶ 2,007:
/*──────────────────────────────────────────────────────────────────────────────────────*/
combSort: procedure expose @.; parse arg N /*N: is the number of @ elements. */
s=N -1 1 /*S: is the spread between COMBs. */
do until s<=1 & done; done=1 /*assume sort is done (so far). */
s=trunc(s * 0.8) % 1 /*Note: ÷ is slow, * is betterfaster.*/
do j=1 until js>=N; js /* [↑] same as: s=j+trunc( s / 1.25) */
if @.do j>@.js=1 thenuntil do;$ _>=@.j; @.j=@.jsN; @.js=_; done$=0; j + ends
end if @.j /*> @.$ then do; _=@.j*/; @.j=@.$; @.$=_; done=0; end
end end /*untilj*/
end /*until*/ /* [↑] swap two elements in the array.*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 2,032:
return /* [↑] adjust # because of the DO loop*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do jk=1 for #; say right(' element' ,15) right(jk,w) arg(1)":" @.jk; end; return</lang>
Data notetrivia: &nbsp; A &nbsp; ''hendecagon'' &nbsp; (also known as an &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'''|:}}
<pre style="height:80ex">
element 1 before sort: ----polygon--- sides