Sorting algorithms/Selection sort: Difference between revisions

Content deleted Content added
Line 672: Line 672:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>selectionSort [] = []
<lang haskell>import Data.List (unfoldr)

selectionSort (first:lst) = selectR first [] lst where
selectR small output [] = small : selectionSort output
selectionSort = unfoldr selectionSort' where
selectionSort' [] = Nothing
selectR small output (x:xs) | x < small = selectR x (small:output) xs
selectionSort' (first:lst) = Just $ foldl f (first, []) lst
| otherwise = selectR small (x:output) xs</lang>
f (small, output) x | x < small = (x, small:output)
| otherwise = (small, x:output)</lang>


=={{header|HaXe}}==
=={{header|HaXe}}==