Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→{{header|Minimal BASIC}}: {{works with|Bywater BASIC|2.61}}) |
(Jakt) |
||
Line 4,232: | Line 4,232: | ||
For the most part, bubble sort works against J's strengths. However, once a single pass has been implemented as a list operation, <code>^:_</code> tells J to repeat this until the result stops changing. |
For the most part, bubble sort works against J's strengths. However, once a single pass has been implemented as a list operation, <code>^:_</code> tells J to repeat this until the result stops changing. |
||
=={{header|Jakt}}== |
|||
<syntaxhighlight lang="jakt"> |
|||
fn bubble_sort<T>(anon mut array: [T]) { |
|||
mut item_count = array.size() |
|||
mut has_changed = true |
|||
while item_count > 1 and has_changed { |
|||
has_changed = true |
|||
item_count-- |
|||
for i in 0..item_count { |
|||
if array[i] > array[i + 1] { |
|||
let temp = array[i] |
|||
array[i] = array[i + 1] |
|||
array[i + 1] = temp |
|||
has_changed = true |
|||
} |
|||
} |
|||
} |
|||
} |
|||
fn main() { |
|||
mut array = [7, 8, 9, 6, 5, 3, 1, 10, 4, 2] |
|||
println("{}", array) |
|||
bubble_sort(array) |
|||
println("{}", array) |
|||
} |
|||
</syntaxhighlight> |
|||
=={{header|Janet}}== |
=={{header|Janet}}== |