Skip to content

Instantly share code, notes, and snippets.

@marchev
Created September 24, 2017 19:03
Show Gist options
  • Save marchev/dd0558d1630a9aa5928cc6404901036f to your computer and use it in GitHub Desktop.
Save marchev/dd0558d1630a9aa5928cc6404901036f to your computer and use it in GitHub Desktop.
Quicksort in Haskell
-- Quicksort in Haskell
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort [x] = [x]
quicksort (x:xs) =
let lessThanOrEqualToXSorted = quicksort [y | y <- xs, y <= x]
greaterThanXSorted = quicksort [z | z <- xs, z > x]
in lessThanOrEqualToXSorted ++ [x] ++ greaterThanXSorted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment