Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→{{header|C++}}) |
(Add Nimrod) |
||
Line 2,137: | Line 2,137: | ||
return \isTrue |
return \isTrue |
||
</lang> |
</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}}== |
=={{header|Objeck}}== |