Skip to content

Instantly share code, notes, and snippets.

@monzou
Created June 16, 2012 08:56
Show Gist options
  • Save monzou/2940583 to your computer and use it in GitHub Desktop.
Save monzou/2940583 to your computer and use it in GitHub Desktop.
qsort @ Haskell
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
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