Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Last active December 14, 2015 07:38
Show Gist options
  • Save lucassmagal/5051727 to your computer and use it in GitHub Desktop.
Save lucassmagal/5051727 to your computer and use it in GitHub Desktop.
qsort :: (Int -> Int -> Bool) -> [Int] -> [Int]
qsort _ [] = []
qsort fn (pivot:elems) =
let p = filter (fn pivot) elems
q = filter (not . fn pivot) elems
in qsort fn p ++ [pivot] ++ qsort fn q
-- qsort (>) [5,2,6,1,87,0,9]
-- [0,1,2,5,6,9,87]
-- qsort (<) [5,2,6,1,87,0,9]
-- [87,9,6,5,2,1,0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment