Sorting algorithms/Sleep sort: Difference between revisions
Content deleted Content added
→{{header|D}}: Simplify D sleep sort implementation |
|||
Line 255: | Line 255: | ||
=={{header|D}}== |
=={{header|D}}== |
||
⚫ | |||
<lang d>import std.stdio, std.conv, std.datetime, std.array, core.thread; |
|||
import core.thread, std.concurrency, std.datetime, |
|||
std.stdio, std.algorithm, std.conv; |
|||
⚫ | |||
final class SleepSorter: Thread { |
|||
{ |
|||
private immutable uint val; |
|||
⚫ | |||
return; |
|||
⚫ | |||
this(in uint n) /*pure nothrow @safe*/ { |
|||
spawn((uint num) { |
|||
Thread.sleep(dur!"msecs"(10 * num)); |
|||
⚫ | |||
} |
|||
}, number); |
|||
thread_joinAll(); |
|||
Thread.sleep(dur!"msecs"(1000 * val)); |
|||
⚫ | |||
} |
|||
} |
} |
||
</lang> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
new SleepSorter(arg.to!uint).start; |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>sorting_algorithms_sleep_sort 1 6 2 5 3 4 |
<pre>sorting_algorithms_sleep_sort 1 6 2 5 3 4 |