Sort stability: Difference between revisions

m
→‎{{header|REXX}}: used the identical sort taken from the REXX entry for bubble sort.
m (→‎{{header|REXX}}: alternated use of literal delimiters (on the same statement).)
m (→‎{{header|REXX}}: used the identical sort taken from the REXX entry for bubble sort.)
Line 861:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bubbleSort: procedure expose @.; parse arg n; m=n-1 /*N: is the number of itemsarray in arrayelements. */
do m=m for m by -1 until ok; ok=1 /*diminishkeep numbersorting ofarray itemsuntil each cycledone. */
do until ok j=1 for m; k=j+1; if @.j<=@.k then iterate /*sort until it's finished sorting. Not out─of─order?*/
ok_=1 @.j; @.j=@.k; @.k=_; ok=0 /*assumeswap it's2 doneelements; flag (1≡true,as 0≡false).¬done*/
do j=1 for n-1 end /*sort N-1 items this time around. j*/
k=j+1 end /*point to the next item to be sorted. m*/
if @.j>@.k then do /*is this array item out-of-order? */
_=@.j /*assign to a temporary variable (_). */
@.j=@.k /*swap current item with the next ··· */
@.k=_ /* ··· and the next with temp var.*/
ok=0 /*indicate it's not done, where ··· */
end /* [↑] 1≡true 0≡false */
end /*j*/
end /*until*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/