Sorting algorithms/Sleep sort: Difference between revisions

Content added Content deleted
(→‎{{header|Scala}}: Replaced very outdated code)
Line 1,406:
=={{header|Scala}}==
<lang scala>object SleepSort {
 
def sort(nums:Seq[Int])=nums foreach {n =>
def main(args: Array[String]): Unit = {
scala.concurrent.ops.spawn{
val nums Thread= args.sleepmap(500*n_.toInt)
printsort(n+" "nums)
Thread.sleep(nums.max * 21) // Keep the JVM alive for the example
}
}
def main(args:Array[String])={
sort(args map (_.toInt))
}
 
def sort(nums: Seq[Int])=nums foreach: {nUnit =>
nums.foreach(i => new Thread {
override def run() {
Thread.sleep(i * 20) // just `i` is unpredictable with small numbers
println(i)
}
}.start())
 
}</lang>
Example:
<pre>&gt;$ scala SleepSort 1 93 86 70 69 5 37 4 2 5 2 08
0 1 2 3 4 5 5 6 7 8 9 </pre>
 
=={{header|Swift}}==