Sorting algorithms/Sleep sort: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 2,169:
8
10
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="vlang">
import time
import sync
 
fn main() {
mut wg := sync.new_waitgroup()
test_arr := [3, 2, 1, 4, 1, 7]
wg.add(test_arr.len)
for i, value in test_arr {
go sort(i, value, mut wg)
}
wg.wait()
println('Printed sorted array')
}
 
fn sort(id int, value int, mut wg sync.WaitGroup) {
time.sleep(value * time.millisecond) // can change duration to second or others
println(value)
wg.done()
}
</syntaxhighlight>
 
{{out}}
<pre>
1
1
2
3
4
7
Printed sorted array
</pre>
 
291

edits