Sorting algorithms/Bubble sort: Difference between revisions

m
Changed over to headers.
(→‎[[Java]]: Use Java header instead.)
m (Changed over to headers.)
Line 22:
=Examples=
 
==[[{{header|Ada]]}}==
[[Category:Ada]]
'''Compiler:''' GCC 4.1.2
 
Line 144 ⟶ 143:
}
 
==[[{{header|Clean]]}}==
[[Category:Clean]]
Bubble sorting an array in-situ (using destructive updates), using Clean's uniqueness typing. We specified the type of <tt>sweep</tt> using strictness annotations to improve performance.
import StdEnv
Line 165 ⟶ 163:
Start = bsort {x \\ x <- [100,99..1]}
 
==[[{{header|E]]}}==
[[Category:E]]
 
def bubbleSort(target) {
Line 184 ⟶ 181:
(Uses the primitive __loop directly because it happens to map to the termination test for this algorithm well.)
 
==[[{{header|Forth]]}}==
[[Category:Forth]]
Sorts the 'cnt' cells stored at 'addr' using the test stored in the deferred word 'bubble-test'. Uses forth local variables for clarity.
 
Line 232 ⟶ 228:
test tcnt cells dump
 
==[[{{header|Haskell]]}}==
[[Category:Haskell]]
This version checks for changes in a separate step for simplicity, because Haskell has no variables to track them with.
bsort :: Ord a => [a] -> [a]
Line 272 ⟶ 267:
}
 
==[[{{header|JavaScript]]}}==
[[Category:JavaScript]]
 
Array.prototype.bubblesort = function() {
Line 289 ⟶ 283:
}
 
==[[{{header|MAXScript]]}}==
[[Category:MAXScript]]
fn bubbleSort arr =
(
Line 312 ⟶ 305:
myArr = bubbleSort myArr
 
==[[{{header|Perl]]}}==
[[Category:Perl]]
'''Interpreter:''' perl 5.8.8
 
Line 361 ⟶ 353:
print join(",", Bubble_Sort(@test));
 
==[[{{header|Pop11]]}}==
[[Category:Pop11]]
 
define bubble_sort(v);
Line 384 ⟶ 375:
ar =>
 
==[[{{header|Python]]}}==
[[Category:Python]]
<pre>
def bubble_sort(seq):
Line 398 ⟶ 388:
</pre>
 
==[[{{header|Ruby]]}}==
[[Category:Ruby]]
Although the native Ruby sort method for Arrays if much faster (O(n*log(n)) versus O(n**2)), you can find a Ruby version of Bubble sort hereunder. It adds the bubblesort! method to the Array object. Below are two different methods that show four different iterating constructs in ruby.
 
Line 431 ⟶ 420:
# => [3, 4, 6, 6, 8, 23, 78]
 
==[[{{header|Seed7]]}}==
[[Category:Seed7]]
const proc: bubbleSort (inout array integer: arr) is func
local
Line 454 ⟶ 442:
bubbleSort(arr);
 
==[[{{header|Toka]]}}==
[[Category:Toka]]
 
Toka does not have a bubble sort predefined, but it is easy to code a simple one:
Anonymous user