Skip to content

Instantly share code, notes, and snippets.

@cnevinc
Created September 29, 2015 00:43
Show Gist options
  • Save cnevinc/e8d3cbf33c8e3b41f1ea to your computer and use it in GitHub Desktop.
Save cnevinc/e8d3cbf33c8e3b41f1ea to your computer and use it in GitHub Desktop.
fun selectionSort(a: IntArray) {
if (a.size() < 1) {
return
}
for( j in 0..a.size() - 1){
var minp = j
for (i in j..a.size() - 1) {
if (a[minp] > a[i]){
minp = i
}
}
println("min started from $j is ${a[minp]} @ $minp")
swap(a,j,minp)
}
}
fun main(args: Array<String>) {
val array = intArrayOf(9, 3, 5, 6, 2, 4)
array.forEach { i -> println(i) }
selectionSort(array)
array.forEach { i -> println(i) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment