Sort the letters of string in alphabetical order: Difference between revisions
Sort the letters of string in alphabetical order (view source)
Revision as of 09:24, 25 July 2021
, 2 years ago→{{header|Haskell}}: Slightly rephrased the question in Haskell
(→{{header|Haskell}}: Added a question in Haskell) |
(→{{header|Haskell}}: Slightly rephrased the question in Haskell) |
||
Line 117:
sort
"Is this misspelling of alphabetical as alphabitical a joke ?"</lang>
{{Out}}
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>
Or, sketching a rough re-phrase of the question:
<lang haskell>main :: IO ()
main =
print $
qSort
"Is this misspelling of alphabetical as alphabitical a joke ?"
qSort :: (Ord a) => [a] -> [a]
qSort [] = []
qSort (x : xs) = before <> [x] <> after
where
before = qSort [c | c <- xs, c <= x]
after = qSort [c | c <- xs, c > x]</lang>
{{Out}}
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>
|