Sort the letters of string in alphabetical order: Difference between revisions

Content added Content deleted
m (added whitespace.)
m (→‎{{header|Haskell}}: Used partition for the rough and ready sort)
Line 150: Line 150:
Or, sketching a rough re-phrase of the question:
Or, sketching a rough re-phrase of the question:


<lang haskell>main :: IO ()
<lang haskell>import Data.List (partition)

main :: IO ()
main =
main =
print $
print $
Line 158: Line 160:
qSort :: (Ord a) => [a] -> [a]
qSort :: (Ord a) => [a] -> [a]
qSort [] = []
qSort [] = []
qSort (x : xs) = cmp (<=) <> (x : cmp (>))
qSort (x : xs) = qSort below <> (x : qSort above)
where
where
cmp p = qSort [v | v <- xs, p v x]</lang>
(below, above) = partition (<= x) xs</lang>
{{Out}}
{{Out}}
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>