Anonymous user
Sorting algorithms/Comb sort: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace.
PatGarrett (talk | contribs) m (→{{header|360 Assembly}}: add a comment) |
m (→{{header|REXX}}: added/changed comments and whitespace.) |
||
Line 1,765:
=={{header|REXX}}==
Programming note: the REXX statement (line 12) <big> '''s=trunc(s*0.8)''' </big> could've been expressed as: <big> '''s=s*0.8%1''' </big> (which is faster), but is more cryptic.
<lang rexx>/*REXX program sorts and displays a stemmed array using the comb sort algorithm.
call gen;
call show 'before sort' /*display the before array elements. */
say copies('▒', 60)
call combSort
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
s=N-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)
do j=1 until js>=N; js=j+s
if @.j>@.js then do; _=@.j; @.j=@.js; @.js=_; done=0; end
end /*j*/
end /*until*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen:
do #=1 while @.#\==''; end; #=#-1 /*find how many
return /* [↑] adjust # because of the DO loop*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do j=1 for #; say ' element' right(j,w) arg(1)":" @.j; end; return</lang>
|