Sorting algorithms/Bubble sort: Difference between revisions

add E example
(adding JavaScript implementation)
(add E example)
Line 142:
Start :: {Int}
Start = bsort {x \\ x <- [100,99..1]}
 
==[[E]]==
[[Category:E]]
 
def bubbleSort(target) {
__loop(fn {
var changed := false
for i in 0..(target.size() - 2) {
def [a, b] := target(i, i + 2)
if (a > b) {
target(i, i + 2) := [b, a]
changed := true
}
}
changed
})
}
 
(Uses the primitive __loop directly because it happens to map to the termination test for this algorithm well.)
 
==[[Forth]]==