Created
September 29, 2015 00:43
-
-
Save cnevinc/e8d3cbf33c8e3b41f1ea to your computer and use it in GitHub Desktop.
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 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