Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, simplified the bubble sort algorithm.
No edit summary |
m (→{{header|REXX}}: added/changed whitespace and comments, simplified the bubble sort algorithm.) |
||
Line 3,323:
=={{header|REXX}}==
<lang rexx>/*REXX program sorts an array (of any items) using the bubble-sort
call gen
call show
call
/*────────────────────────────────────────────────────────────────────────────*/
bubbleSort: procedure expose @.; parse arg n
m=n-1
do j=1 for
if @.j>@.k
▲ done=0 /*indicate it's not done, whereas*/
end /*j*/
return
/*────────────────────────────────────────────────────────────────────────────*/
gen
@.1 = '---letters of the Hebrew alphabet---' ; @.13 = 'kaph [kaf]'
@.2 = '====================================' ; @.14 = 'lamed'
@.3 = 'aleph [alef]' ; @.15 = 'mem'
@.4 = 'beth [bet]' ; @.16 = 'nun'
@.5 = 'gimel' ; @.17 = 'samekh'
@.6 = 'daleth [dalet]' ; @.18 = 'ayin'
@.7 = 'he' ; @.19 = 'pe'
@.8 = 'waw [vav]' ; @.20 = 'sadhe [tsadi]'
@.9 = 'zayin' ; @.21 = 'qoph [qof]'
@.10 = 'heth [het]' ; @.22 = 'resh'
@.11 = 'teth [tet]' ; @.23 = 'shin'
@.12 = 'yod' ; @.24 = 'taw [tav]'
do #=1 while @.#\==''; end; #=#-1 /*find how many elements in list.*/
w=length(#)
/*────────────────────────────────────────────────────────────────────────────*/
'''output''' when using the internal array list:
▲ say 'element' right(j,widthH) arg(1)':' @.j
<pre style="height:30ex">
element 1 before sort: ---letters of the Hebrew alphabet---
Line 3,397 ⟶ 3,388:
element 23 before sort: shin
element 24 before sort: taw [tav]
───────────────────────────────────────────────────────────────────────────────
element 1 after sort: ---letters of the Hebrew alphabet---
element 2 after sort: ====================================
Line 3,422 ⟶ 3,413:
element 23 after sort: yod
element 24 after sort: zayin
</pre>
|