Created
January 11, 2022 13:22
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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