3 ms·
Quicksort in Haskell quicksort :: (Ord a) => [a] -> [a] quicksort [] = [] quicksort (x:xs) = let smallerSorted = quicksort [a | a <-
by e19293001 10y ago
Quicksort in Haskell
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
Source: http://learnyouahaskell.com/recursion#hello-recursion http://learnyouahaskell.com/recursion#hello-recursion
- tome 10y ago(Technically this is not quicksort, unless you're willing to be particularly broad with your definition of quicksort)