Anonymous user
Sort stability: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations, simplified a subroutine.
m (→{{header|REXX}}: changed a comment.) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations, simplified a subroutine.) |
||
Line 853:
=={{header|REXX}}==
Classic REXX has no built-in routines for sorting, so this programming example uses a classic ''bubble sort'' (which is stable).
<lang rexx>/*REXX program sorts
call gen@ /*generate the array elements
call show
call
/*──────────────────────────────────────────────────────────────────────────────────────*/
bubbleSort: procedure expose @.; parse arg n /*N: is the number
if @.j>@.k then do
end /*
return▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen@: @.=; @.1 = 'UK London'
@.2 = 'US New York'
@.3 = 'US Birmingham'
@.4 = 'UK Birmingham'
▲ return
▲ do #=1 while @.# \=='' /*find how many entries in list. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ end /*#*/
▲#=#-1 /*adjust because of DO increment.*/
▲ say ' element' right(j,length(#)) arg(1)':' @.j
▲ end /*j*/
'''output''' using the default list:
<pre>
Line 898 ⟶ 891:
element 3 before sort: US Birmingham
element 4 before sort: UK Birmingham
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
element 1 after sort: UK Birmingham
element 2 after sort: UK London
element 3 after sort: US Birmingham
element 4 after sort: US New York
</pre>
|