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

Content added Content deleted
(→‎{{header|Haskell}}: Added a question in Haskell)
(→‎{{header|Haskell}}: Slightly rephrased the question in Haskell)
Line 117: Line 117:
sort
sort
"Is this misspelling of alphabetical as alphabitical a joke ?"</lang>
"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}}
{{Out}}
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>