Sorting algorithms/Sleep sort: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) m (→{{header|REXX}}: tidy up) |
(→{{header|Haskell}}: tabs->spaces; type sig; discussion) |
||
Line 608:
sleepSort :: [Int] -> IO ()
sleepSort values = do
main :: IO ()
Line 620:
import Control.Concurrent.Async
sleepSort :: [Int] -> IO
sleepSort = (() <$) . mapConcurrently (\x -> threadDelay (x*10^4) >> print x)
main :: IO
main = getArgs >>= sleepSort . map read</lang>
This is problematic for inputs with multiple duplicates like <code>[1,2,3,1,4,1,5,1]</code> because simultaneous <code>print</code>s are done concurrently and the 1s and newlines get output in jumbled up order. The channels-based version above doesn't have this problem.
=={{header|Icon}} and {{header|Unicon}}==
|