Anonymous user
Sorting algorithms/Bogosort: Difference between revisions
m
→true bogo sort: changed the output titles, ensured that the random numbers were unique (for swapping)..
m (→{{header|REXX}}: corrected a statement, found by Walter Pachl, reduced number of comparisons by ½.) |
m (→true bogo sort: changed the output titles, ensured that the random numbers were unique (for swapping)..) |
||
Line 1,769:
=={{header|REXX}}==
===true bogo sort===
<lang rexx>/*REXX program performs a type of bogo sort on numbers in an array.
parse arg list /*obtain optional list from C.L. */
if list='' then list=-21 333 0 444.4 /*Not defined? Then use default.*/
#=words(list) /*the
do i=1 for words(list);
call tell '
do bogo=1
do j=1 for #-1; jp=j+1
if @.jp>=@.j then iterate
parse value @.a
iterate bogo /*go and try another bogo sort. */
end /*j*/
leave /*we're finished with bogo sort. */
end /*bogo*/ /* [↓] show the # of bogo sorts.*/
say 'number of bogo sorts performed =' bogo
call tell ' after bogo
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────TELL subroutine─────────────────────*/
tell: say;
say
return</lang>
{{out}} using the default input:
<pre>
─────────────────before bogo sort─────────────────
number of bogo sorts performed =
───────────────── after bogo sort─────────────────
after bogo
after bogo
after bogo
after bogo
</pre>
|