2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -11,4 +11,6 @@ Similarly, stable sorting on just the first column would generate “UK London
|
|||
#Indicate if an in-built routine is supplied
|
||||
#If supplied, indicate whether or not the in-built routine is stable.
|
||||
|
||||
<br>
|
||||
(This [[wp:Stable_sort#Comparison_of_algorithms|Wikipedia table]] shows the stability of some common sort routines).
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,39 +1,24 @@
|
|||
/*REXX program sorts an array using a (stable) bubble-sort algorithm.*/
|
||||
call gen@ /*generate the array elements. */
|
||||
call show@ 'before sort' /*show the before array elements.*/
|
||||
call bubbleSort # /*invoke the bubble sort. */
|
||||
call show@ ' after sort' /*show the after array elements.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────BUBBLESORT subroutine───────────────*/
|
||||
bubbleSort: procedure expose @.; parse arg n /*N: number of items.*/
|
||||
/*diminish # items each time. */
|
||||
do until done /*sort until it's done. */
|
||||
done=1 /*assume it's done (1 ≡ true). */
|
||||
do j=1 for n-1 /*sort M items this time around. */
|
||||
k=j+1 /*point to the next item. */
|
||||
if @.j>@.k then do /*is it out of order? */
|
||||
_=@.j /*assign to a temp variable. */
|
||||
@.j=@.k /*swap current item with next ···*/
|
||||
@.k=_ /* ··· and the next with _ */
|
||||
done=0 /*indicate it's not done, whereas*/
|
||||
end /* [↑] 1≡true 0≡false */
|
||||
end /*j*/
|
||||
end /*until*/
|
||||
return
|
||||
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
|
||||
gen@: @. = /*assign default value to all @. */
|
||||
@.1 = 'UK London'
|
||||
@.2 = 'US New York'
|
||||
@.3 = 'US Birmingham'
|
||||
@.4 = 'UK Birmingham'
|
||||
|
||||
do #=1 while @.# \=='' /*find how many entries in list. */
|
||||
end /*#*/
|
||||
#=#-1 /*adjust because of DO increment.*/
|
||||
return
|
||||
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
|
||||
show@: do j=1 for # /* [↓] display all list elements*/
|
||||
say ' element' right(j,length(#)) arg(1)':' @.j
|
||||
end /*j*/
|
||||
say copies('■',50) /*show a separator line. */
|
||||
return
|
||||
/*REXX program sorts a (stemmed) array using a (stable) bubble─sort algorithm. */
|
||||
call gen@ /*generate the array elements (strings)*/
|
||||
call show 'before sort' /*show the before array elements. */
|
||||
say copies('▒', 50) /*show a separator line between shows. */
|
||||
call bubbleSort # /*invoke the bubble sort. */
|
||||
call show ' after sort' /*show the after array elements. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
bubbleSort: procedure expose @.; parse arg n; m=n-1 /*N: number of array elements. */
|
||||
do m=m for m by -1 until ok; ok=1 /*keep sorting array until done.*/
|
||||
do j=1 for m; k=j+1; if @.j<=@.k then iterate /*Not out─of─order?*/
|
||||
_=@.j; @.j=@.k; @.k=_; ok=0 /*swap 2 elements; flag as ¬done*/
|
||||
end /*j*/
|
||||
end /*m*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
gen@: @.=; @.1 = 'UK London'
|
||||
@.2 = 'US New York'
|
||||
@.3 = 'US Birmingham'
|
||||
@.4 = 'UK Birmingham'
|
||||
do #=1 while @.#\==''; end; #=#-1 /*determine how many entries in list. */
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: do j=1 for #; say ' element' right(j,length(#)) arg(1)":" @.j; end; return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue