Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, use shorter index (variable) names.
m (→{{header|REXX}}: added/changed comments and whitespace, use shorter index (variable) names.) |
|||
Line 3,087:
<lang rexx>/*REXX program sorts an array using the bubble-sort algorithm. */
call gen@ /*generate the array elements. */
call show@ 'before sort'
call bubbleSort
call show@ ' after sort'
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────BUBBLESORT subroutine───────────────*/
Line 3,100:
if @.j>@.k then do /*is it out of order? */
_=@.j /*assign to a temp variable. */
@.j=@.k /*swap current item with next
@.k=_ /*
done=0 /*indicate it's not done,
end /* [↑]
end /*j*/▼
end /*j*/
end /*until done*/
Line 3,110 ⟶ 3,109:
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
gen@: @.= /*assign default value to all @. */
@.1 = '---letters of the Hebrew alphabet---'
@.2 = '===================================='
@.3 = 'aleph [alef]'
@.4 = 'beth [bet]'
@.5 = 'gimel'
@.6 = 'daleth [dalet]'
@.7 = 'he'
@.8 = 'waw [vav]'
@.9 = 'zayin'
@.10 = 'heth [het]'
@.11 = 'teth [tet]'
@.12 = 'yod'
#=#-1 /*adjust because of DO increment.*/
return
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
show@: widthH=length(
do j=1 for
say 'element' right(j,widthH) arg(1)':' @.j
end /*j*/
say copies('─',80) /*show a separator line. */
return</lang>
|