Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments and whitespace, use shorter index (variable) names.) |
|||
Line 3,087: | Line 3,087: | ||
<lang rexx>/*REXX program sorts an array using the bubble-sort algorithm. */ |
<lang rexx>/*REXX program sorts an array using the bubble-sort algorithm. */ |
||
call gen@ /*generate the array elements. */ |
call gen@ /*generate the array elements. */ |
||
call show@ 'before sort' |
call show@ 'before sort' /*show the before array elements.*/ |
||
call bubbleSort |
call bubbleSort # /*invoke the bubble sort. */ |
||
call show@ ' after sort' |
call show@ ' after sort' /*show the after array elements.*/ |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*──────────────────────────────────BUBBLESORT subroutine───────────────*/ |
/*──────────────────────────────────BUBBLESORT subroutine───────────────*/ |
||
Line 3,100: | Line 3,100: | ||
if @.j>@.k then do /*is it out of order? */ |
if @.j>@.k then do /*is it out of order? */ |
||
_=@.j /*assign to a temp variable. */ |
_=@.j /*assign to a temp variable. */ |
||
@.j=@.k /*swap current with next |
@.j=@.k /*swap current item with next ···*/ |
||
@.k=_ /* |
@.k=_ /* ··· and the next with _ */ |
||
done=0 /*indicate it's not done, |
done=0 /*indicate it's not done, whereas*/ |
||
end /* |
end /* [↑] 1≡true 0≡false */ |
||
⚫ | |||
end /*j*/ |
end /*j*/ |
||
end /*until done*/ |
end /*until done*/ |
||
Line 3,110: | Line 3,109: | ||
/*──────────────────────────────────GEN@ subroutine─────────────────────*/ |
/*──────────────────────────────────GEN@ subroutine─────────────────────*/ |
||
gen@: @.= /*assign default value to all @. */ |
gen@: @.= /*assign default value to all @. */ |
||
@.1 ='---letters of the Hebrew alphabet---' |
@.1 = '---letters of the Hebrew alphabet---' ; @.13 = 'kaph [kaf]' |
||
@.2 ='====================================' |
@.2 = '====================================' ; @.14 = 'lamed' |
||
@.3 ='aleph [alef]' |
@.3 = 'aleph [alef]' ; @.15 = 'mem' |
||
@.4 ='beth [bet]' |
@.4 = 'beth [bet]' ; @.16 = 'nun' |
||
@.5 ='gimel' |
@.5 = 'gimel' ; @.17 = 'samekh' |
||
@.6 ='daleth [dalet]' |
@.6 = 'daleth [dalet]' ; @.18 = 'ayin' |
||
@.7 ='he' |
@.7 = 'he' ; @.19 = 'pe' |
||
@.8 ='waw [vav]' |
@.8 = 'waw [vav]' ; @.20 = 'sadhe [tsadi]' |
||
@.9 ='zayin' |
@.9 = 'zayin' ; @.21 = 'qoph [qof]' |
||
@.10='heth [het]' |
@.10 = 'heth [het]' ; @.22 = 'resh' |
||
@.11='teth [tet]' |
@.11 = 'teth [tet]' ; @.23 = 'shin' |
||
@.12='yod' |
@.12 = 'yod' ; @.24 = 'taw [tav]' |
||
do highItem=1 while @.highItem\=='' /*find how many entries in list. */ |
|||
end /*highitem*/ |
|||
do #=1 while @.# \=='' /*find how many entries in list. */ |
|||
⚫ | |||
#=#-1 /*adjust because of DO increment.*/ |
|||
return |
return |
||
/*──────────────────────────────────SHOW@ subroutine────────────────────*/ |
/*──────────────────────────────────SHOW@ subroutine────────────────────*/ |
||
show@: widthH=length( |
show@: widthH=length(#) /*maximum width of any line. */ |
||
do j=1 for |
do j=1 for # |
||
say 'element' right(j,widthH) arg(1)':' @.j |
say 'element' right(j,widthH) arg(1)':' @.j |
||
end /*j*/ |
end /*j*/ |
||
say copies('─',80) /*show a separator line. */ |
say copies('─',80) /*show a separator line. */ |
||
return</lang> |
return</lang> |