Created
June 16, 2012 08:56
-
-
Save monzou/2940583 to your computer and use it in GitHub Desktop.
qsort @ Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print $ quicksort [ 10, 2, 5, 3, 1, 6, 7, 2, 3, 4, 8, 9 ] | |
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let | |
le = filter (<= x) xs | |
gt = filter (> x) xs | |
in quicksort le ++ [x] ++ quicksort gt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print $ quicksort [ 10, 2, 5, 3, 1, 6, 7, 2, 3, 4, 8, 9 ] | |
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let | |
le = [a | a <- xs, a <= x] | |
gt = [a | a <- xs, a > x] | |
in quicksort le ++ [x] ++ quicksort gt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment