Created
October 13, 2018 19:00
-
-
Save vamsitallapudi/795785850c9ee0f1b6af463182a1f554 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 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