Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created October 13, 2018 19:00
Show Gist options
  • Save vamsitallapudi/795785850c9ee0f1b6af463182a1f554 to your computer and use it in GitHub Desktop.
Save vamsitallapudi/795785850c9ee0f1b6af463182a1f554 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
val list = ArrayList(readLine()!!.split(" ").map { it.toInt() })
selection(list)
for(i in list) println(i)
}
fun selection(a: ArrayList<Int>) {
var min:Int
for (i in 0 until a.size) {
min = i
for (j in (i + 1) until a.size) {
if (a[j] < a[min]) {
min = j
}
}
swap(a, min, i)
}
}
fun swap(a : ArrayList<Int>, b: Int, c:Int) {
val temp = a[b]
a[b] = a[c]
a[c] = temp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment