Sorting algorithms/Bubble sort: Difference between revisions

Add Nimrod
(Add Nimrod)
Line 2,137:
return \isTrue
</lang>
 
=={{header|Nimrod}}==
<lang nimrod>proc bubbleSort[T](a: var openarray[T]) =
var
j = 1
t = true
for n in countdown(a.len-2, 0):
if not t: break
t = false
for j in 0..n:
if a[j] <= a[j+1]: continue
swap a[j], a[j+1]
t = true
 
var a = @[4, 65, 2, -31, 0, 99, 2, 83, 782]
bubbleSort a
echo a</lang>
Output:
<pre>@[-31, 0, 2, 2, 4, 65, 83, 99, 782]</pre>
 
=={{header|Objeck}}==
Anonymous user