Skip to content

Instantly share code, notes, and snippets.

@Makiyu-py
Created January 11, 2022 13:22
Show Gist options
  • Save Makiyu-py/6bc5798ce2edc4ca78d0913d51516490 to your computer and use it in GitHub Desktop.
Save Makiyu-py/6bc5798ce2edc4ca78d0913d51516490 to your computer and use it in GitHub Desktop.
A Kotlin Implementation of Bubble Sort :D (bubble sort is the starter "project" that I do when learning new langs)
fun main() {
var arr = arrayOf(4, 1, 3, 7, 6, 5, 8, 2)
println(arr.contentToString())
for (i in 1..arr.size) {
for (j in 0..arr.size-i-1) {
if (arr[j] > arr[j+1]) {
arr[j] = arr[j+1].also { arr[j+1] = arr[j] }
}
var outArr = arr.contentToString()
println("iter $i.$j | $outArr")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment