Sorting algorithms/Bubble sort: Difference between revisions

m
→‎{{header|REXX}}: simplified bSort code.
m (→‎{{header|REXX}}: simplified bSort code.)
Line 3,857:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bSort: procedure expose @.; parse arg n; m=n-1 /*N: is the number of @ array elements.*/
do m=mn-1 for m by -1 until ok; ok=1 /*keep sorting the @ array until done.*/
do j=1 for m; k=j+1; if @.j<=@.k then iterate /*elements in order? */
_=@.j; @.j=@.k; @.k=_; ok=0 /*swap two elements; flag as not done.*/
end /*j*/
end /*m*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: @.=; @.1 = '---letters of the Hebrew alphabet---' ; @.13= "kaph [kaf]"
Line 3,946:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bSort: procedure expose @.; parse arg n; m=n-1 /*N: is the number of @ array elements.*/
do m=mn-1 by -1 until ok; ok=1 /*keep sorting the @ array until done.*/
do j=1 for m; k=j+1; if @.j>@.k then parse value @.j @.k 0 with @.k @.j ok
end /*j*/ /* [↑] swap 2 elements, flag as ¬done.*/
Line 4,010:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bSort: procedure expose @.; parse arg #; m=#-1 /*N: is the number of @ array elements.*/
call disp /*show a snapshot of the unsorted array*/
do m=m #-1 by -1 until ok; ok=1 /*keep sorting the @ array until done.*/
do j=1 for m; k=j+1
if @.j>@.k then do; parse value @.j @.k 0 with @.k @.j ok
end
end /*j*/ /* [↑] swap 2 elements, flag as ¬done.*/
call disp /*show snapshot of particallypartially sorted @. */
end /*m*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/