Sorting algorithms/Comb sort: Difference between revisions

m
→‎{{header|REXX}}: changed comments and indentations, reduce output fence by one byte. -- ~~~~.
m (→‎{{header|REXX}}: corrected a misspelling. -- ~~~~)
m (→‎{{header|REXX}}: changed comments and indentations, reduce output fence by one byte. -- ~~~~.)
Line 1,250:
 
=={{header|REXX}}==
<lang rexx>/*REXX program sorts an array using the comb-sort method. */
call gen@ /*generate the array elements. */
call show@ 'before sort' /*show the before array elements.*/
call combSort highItem /*invoke the comb sort. */
call show@ ' after sort' /*show the after array elements.*/
exit /*stick a fork in it, we're done.*/
exit
/*──────────────────────────────────COMBSORT subroutine─────────────────*/
/*─────────────────────────────────────COMBSORT subroutine─────────*/
combSort: procedure expose @.; parse arg n
s=n-1 /*S = spread between COMBs. */
 
do until s<=1 & done
s=trunc(s*.8) /* ÷ is slow, * is better. */
done=1
do j=1 until j+s>=n
jps=j+s
if @.j>@.jps then do; _=@.j; @.j=@.jps; @.jps=_; done=0; end
end /*j*/
end /*until*/
end
 
return
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
/*─────────────────────────────────────GEN@ subroutine─────────────*/
gen@: @.='' /*assign the default value. */
@.1 ='--- polygon sides'
@.2 ='============== ====='
Line 1,283:
@.10='decagon 10'
@.11='dodecagon 12'
do highItem=1 while @.highItem\=='' /*find how many entries. in array.*/
 
do highItem=1 while @.highItem\=='' /*find how many entries. */
end
highItem=highItem-1 /*adjust highItem slightly. */
 
highItem=highItem-1 /*adjust highItem slightly. */
return
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
/*─────────────────────────────────────SHOW@ subroutine────────────*/
show@: widthH=length(highItem) /*the maximum width of any line. */
do j=1 for highItem
 
say 'element' right(j,widthH) arg(1)":" @.j
do j=1 for highItem
end
say 'element' right(j,widthH) arg(1)":" @.j
say copies('─',8079) /*show a nice separator line. */
end
 
say copies('─',80) /*show a separator line. */
return</lang>
'''output'''
Line 1,311 ⟶ 1,307:
element 10 before sort: decagon 10
element 11 before sort: dodecagon 12
───────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────
 
element 1 after sort: --- polygon sides
Line 1,324 ⟶ 1,320:
element 10 after sort: quadrilateral 4
element 11 after sort: triangle 3
───────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────
</pre>