Anonymous user
Sorting algorithms/Sleep sort: Difference between revisions
m
→{{header|REXX}}: added a section header comment (only works with ...), changed/add comments and indentations, added whitespace.
m (→{{header|REXX}}: removed STYLE from the PRE html tag.) |
m (→{{header|REXX}}: added a section header comment (only works with ...), changed/add comments and indentations, added whitespace.) |
||
Line 904:
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 C.L.)*/▼
This REXX version '''only''' works with Regina REXX (as the program uses the '''fork''' func tion.
<br>REXX isn't particular what is being sorted.
numeric digits 300 /*over the top, but what the hey!*/
/* (above)
#.= /*placeholder for the array of #s*/
stuff=
parse arg numbers /*let the user specify on the CL.*/
if numbers='' then numbers=stuff
N=words(numbers) /*N is the number of numbers. */
w=length(N) /*width of N (for nice output).*/
say N 'numbers to be sorted:' numbers /*informative informational info.*/
do j=1 for N
#.j=word(numbers,j) /*plug in one number at a time. */
if datatype(#.j,'
call fork /*only REGINA REXX supports FORK
call sortItem j /*start a sort for array number. */
end /*j*/
do forever while \inOrder(N)
call sleep 1 /*1 sec is
end /*forever while*/ /*well, other than zero seconds. */
m=max(length(#.1),length(#.N)) /*width of smallest | largest num*/
say; say 'after sort:'
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────────SortItem subroutine────────────────*/
sortItem:
return /*Sleeping Beauty awakes. Not to worry: (c) = circa 1697.*/
/*───────────────────────────────────InOrder subroutine─────────────────*/
inOrder: procedure expose #.; parse arg howMany /*is array in order? */
do m=1 for howMany-1; next=m+1;
end /*m*/ /*keep looking for fountain of yut*/
return 1 /*yes, indicate with an indicator.*/
</lang>
'''output''' when using the default input
<pre>
|