June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,23 @@
|
|||
// version 1.1.51
|
||||
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
fun sleepSort(list: List<Int>, interval: Long) {
|
||||
print("Sorted : ")
|
||||
for (i in list) {
|
||||
thread {
|
||||
Thread.sleep(i * interval)
|
||||
print("$i ")
|
||||
}
|
||||
}
|
||||
thread { // print a new line after displaying sorted list
|
||||
Thread.sleep ((1 + list.max()!!) * interval)
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val list = args.map { it.toInt() }.filter { it >= 0 } // ignore negative integers
|
||||
println("Unsorted: ${list.joinToString(" ")}")
|
||||
sleepSort(list, 50)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue