Anonymous user
Sorting algorithms/Sleep sort: Difference between revisions
→{{header|REXX}}: changed comments and whitespace, updated the output to reflect changed glyphs.
(Added Wren) |
(→{{header|REXX}}: changed comments and whitespace, updated the output to reflect changed glyphs.) |
||
Line 1,549:
=={{header|REXX}}==
This sort will accept any manner of numbers, or for that matter, any character string as well.
<br>REXX isn't particular what is being sorted.
<lang rexx>/*REXX program implements a sleep sort (with numbers entered from
numeric digits 300 /*over the top, but what the hey! */
/* (above) ··· from vaudeville. */
@.= /*placeholder for the array of numbers.*/
▲<lang rexx>/*REXX program implements a sleep sort (with numbers entered from C.L.).*/
parse arg
parse upper version !ver . /*obtain which REXX we're running under*/
/*from department of redundancy depart.*/
do j=1 for N /*let's start to boogie─woogie da sort.*/
if
call
end /*j*/
do forever while \inOrder(N) /*wait for the sorts to complete. */
call
end /*forever while*/ /*well heck, other than zero seconds. */
m= max(length(
say;
do k=1 for N /*list the (sorted) array's elements.*/
say left('', 20) 'array element' right(k, w) '───►' right(
end /*k*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sortItem: procedure expose
do Asort=1 until \switched
switched= 0 /*it's all hunky─dorey, happy─dappy
do i=1 while
if
parse value
switched= 1 /* [↑] swapped one.*/
end /*i*/
if Asort//?==0 then call
end /*Asort*/
return /*Sleeping Beauty awakes.
/*──────────────────────────────────────────────────────────────────────────────────────*/
inOrder: procedure expose
do m=1 for howMany-1;
end /*m*/ /*keep looking for fountain of
return 1 /*yes, indicate with an indicator. */</lang>
▲'''output''' when using the default input
<pre>
19 numbers to be sorted:
after sort:
array element 1
array element 2
array element 3
array element 4
array element 5
array element 6
array element 7
array element 8
array element 9
array element 10
array element 11
array element 12
array element 13
array element 14
array element 15
array element 16
array element 17
array element 18
array element 19
</pre>
|