Anonymous user
Sorting algorithms/Insertion sort: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, added a title separator, extended the fence (width).
m (→{{header|REXX}}: added/changed comments and whitespace, added a title separator, extended the fence (width).) |
|||
Line 2,142:
=={{header|REXX}}==
<lang rexx>/*REXX program sorts a stemmed array (has characters) using the insertion sort algorithm*/
call gen /*generate the array's (data) elements.
call show 'before sort' /*display the before array elements. */
say copies('▒',
call insertionSort # /*invoke the insertion sort. */
call show ' after sort' /*display the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen:
@.2 = "
@.3 = "
@.4 = "
@.5 = "
@.6 = "
@.7 = "
@.8 = "
@.9 = "
@.10 = "Is blithe and bonny, good and gay."
do #=1 while @.#\==''; end; #=#-1 /*determine how many entries in @ array*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
insertionSort: procedure expose @.;
do i=2 to #;
_=j+1;
/*──────────────────────────────────────────────────────────────────────────────────────*/
show:
'''output''' when using the internal data:
<pre>
element 1 before sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element 2 before sort:
element 3 before sort:
element 4 before sort:
element 5 before sort:
element 6 before sort:
element 7 before sort:
element 8 before sort:
element 9 before sort:
element 10 before sort: Is blithe and bonny, good and gay.
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
element 1 after sort: ---Monday's Child Is Fair of Face (by Mother Goose)---▼
element
element
element
element
element
element
element
element
▲ element
element 10 after sort: Wednesday's child is full of woe;
</pre>
|