Sorting algorithms/Insertion sort: Difference between revisions

m
→‎{{header|REXX}}: added whitespace and a comment, used a template for the output section.
No edit summary
m (→‎{{header|REXX}}: added whitespace and a comment, used a template for the output section.)
Line 3,215:
call gen /*generate the array's (data) elements.*/
call show 'before sort' /*display the before array elements. */
say copies('▒', 85) /*display a separator line (a fence). */
call insertionSort # /*invoke the insertion sort. */
call show ' after sort' /*display the after array elements. */
Line 3,230:
@.9 = "But the child that is born on the Sabbath day"
@.10 = "Is blithe and bonny, good and gay."
do #=1 while @.#\==''; end; #= #-1 /*determine how many entries in @ array*/
return /* [↑] adjust # for the DO loop index.*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
insertionSort: procedure expose @.; parse arg #
do i=2 to #; $= @.i; do j=i-1 by -1 to 1 while @.j>$
_= j + 1; @._= @.j
end /*j*/
_= j + 1; @._= $
end /*i*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do j=1 for #; say ' element' right(j,length(#)) arg(1)": " @.j; end; return</lang>
'''{{out|output''' |text=&nbsp; when using the default internal data:}}
<pre>
element 1 before sort: ---Monday's Child Is Fair of Face (by Mother Goose)---