Skip to content

Instantly share code, notes, and snippets.

@kaveet
Last active November 15, 2016 19:01
Show Gist options
  • Save kaveet/681a5c991f3d7a6eb5bfc4d55897e427 to your computer and use it in GitHub Desktop.
Save kaveet/681a5c991f3d7a6eb5bfc4d55897e427 to your computer and use it in GitHub Desktop.
Haskell Quicksort Implementation
module Quicksort where
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = quicksort [y | y <- xs, y <= x] ++ [x] ++ quicksort [y | y <- xs, y > x]
quicksort' :: (Ord a) => [a] -> [a]
quicksort' [] = []
quicksort' (x:xs) = (quicksort' small) ++ [x] ++ (quicksort' big)
where
small = filter (< x) xs
big = filter (>= x) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment