Sort an integer array: Difference between revisions

m
→‎sort a list: added/changed some statements, comments, and whitespace, used a template for the output section.
m (→‎sort an array: added/changed statements, comments, and whitespace, used a template for the output section, changed output indentation.)
m (→‎sort a list: added/changed some statements, comments, and whitespace, used a template for the output section.)
Line 1,674:
===sort a list===
This REXX version creates a list with a bunch of interesting integers, then sorts it.
 
<br>Because it so much more efficient to sort an array, &nbsp; an array is built from the list,
<br>it is then sorted, &nbsp; and then the list is re-constituted.
<lang rexx>/*REXX program sorts (using E─sort) and displays a list of some interesting integers. */
Bell= 1 1 2 5 15 52 203 877 4140 21147 115975 /*a few Bell " */
Line 1,694 ⟶ 1,695:
exit /*stick a fork in it, we're all done.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose @.; parse arg N; h=N /*get item count for array. /*an eXchange sort.*/
do while h>1; h= h%2 /*partitiondefine thea arraysegment. */
do i=1 for N-h; j=i; k= h+i /*sort top segment.*/
do while @.k<@.j /*keepsee swappingif whileneed lessswap. */
parse value @.j @.k with @.k @.j /*swap two array elements. */
if h>=j then leave; j= j-h; k= k-h /*this part sorted?*/
end /*while @.k<@.j*/
end /*i*/
end end /*while h>1*/
return</lang>
{{out|output|text=&nbsp; when using the default internal inputs:}}
'''output'''
<pre>
unsorted = 1 1 2 5 15 52 203 877 4140 21147 115975 1 -1 1 0 -1 0 1 0 -1 0 5 0 -691 0 7 0 -3617 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90