Jump to content

Sorting algorithms/Bubble sort: Difference between revisions

m
→‎{{header|REXX}}: removed some blank lines. -- ~~~~
No edit summary
m (→‎{{header|REXX}}: removed some blank lines. -- ~~~~)
Line 2,279:
 
=={{header|REXX}}==
<lang rexx>/*REXX program sorts an array using the bubble-sort method. */
<lang rexx>
/*REXX program sorts an array using the bubble-sort method. */
 
call gen@ /*generate array elements. */
Line 2,287 ⟶ 2,286:
call show@ ' after sort' /*show after array elements*/
exit
 
 
/*─────────────────────────────────────BUBBLESORT subroutine───────*/
bubbleSort: procedure expose @.; parse arg n /*n=number of items.*/
Line 2,294 ⟶ 2,291:
do until done /*sort until it's done. */
done=1 /*assume it's done (1=true).*/
do j=1 for endn-1 /*sort 1=true 0=false M items this time. */
 
do j k=j+1 for n-1 /*sortpoint to next item. M items this time. */
k=j+1 if @.j>@.k then do /*out of order ? /*point to next item. */
if @.j>@.k then do /*out of order ?_=@.j /*assign to a temp variable.*/
_=@.j @.j=@.k /*assignswap tocurrent awith temp variablenext. */
@.j=@.k @.k=_ /*swap... currentand next with next._ */
@.k=_ done=0 /*... and next with _ indicate it's not done. */
done=0 end /*indicate it's not done.1=true 0=false */
end
end /* 1=true 0=false */
end
 
end
 
return
 
 
/*─────────────────────────────────────GEN@ subroutine─────────────*/
gen@: @.='' /*assign default value. */
 
@.1 ='---letters of the Hebrew alphabet---'
@.2 ='===================================='
Line 2,343 ⟶ 2,334:
highItem=highItem-1 /*adjust highItem slightly. */
return
 
 
/*─────────────────────────────────────SHOW@ subroutine────────────*/
show@: widthH=length(highItem) /*maximum width of any line.*/
do j=1 for highItem
 
say 'element' right(j,widthH) arg(1)':' @.j
do j=1 for highItem
end
say 'element' right(j,widthH) arg(1)':' @.j
end
 
say copies('─',80) /*show a seperator line. */
return</lang>
'''output'''
</lang>
Output:
<pre style="height:30ex;overflow:scroll">
element 1 before sort: ---letters of the Hebrew alphabet---
Cookies help us deliver our services. By using our services, you agree to our use of cookies.