Sorting algorithms/Bubble sort: Difference between revisions

m (unnecessary test)
Line 1,684:
hasChanged := true]].
hasChanged] whileTrue.</lang>
 
=={{header|SNOBOL4}}==
 
{{works with|Macro Spitbol}}
{{works with|Snobol4+}}
{{works with|CSnobol}}
 
<lang SNOBOL4>* # Sort array in place, return array
define('bubble(a,alen)i,j,ub,tmp') :(bubble_end)
bubble i = 1; ub = alen
outer gt(ub,1) :f(bdone)
j = 1
inner le(a<j>, a<j + 1>) :s(incrj)
tmp = a<j>
a<j> = a<j + 1>
a<j + 1> = tmp
incrj j = lt(j + 1,ub) j + 1 :s(inner)
ub = ub - 1 :(outer)
bdone bubble = a :(return)
bubble_end
 
* # Fill array with test data
str = '33 99 15 54 1 20 88 47 68 72'
output = str; arr = array(10)
floop i = i + 1; str span('0123456789') . arr<i> = :s(floop)
 
* # Test and display
bubble(arr,10); str = ''
sloop j = j + 1; str = str arr<j> ' ' :s(sloop)
output = trim(str)
end</lang>
 
Output:
<pre>33 99 15 54 1 20 88 47 68 72
1 15 20 33 47 54 68 72 88 99</pre>
 
=={{header|TI-83 BASIC}}==
Anonymous user