Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(Initial Kotlin implementation)
Line 1,541: Line 1,541:
Output:
Output:
A,B,C,D,E,F,G
A,B,C,D,E,F,G

=={{header|Kotlin}}==
{{trans|Java}}

<lang kotlin>fun <T> bubbleSort(a : Array<T>, c: Comparator<T>) {
var changed = false
do {
changed = false
for (i in 0 .. a.size - 2) {
if (c.compare(a[i], a[i + 1]) > 0) {
val tmp = a[i]
a[i] = a[i + 1]
a[i + 1] = tmp
changed = true
}
}
} while (changed)
}</lang>


=={{header|Io}}==
=={{header|Io}}==