Last active
December 14, 2015 07:38
-
-
Save lucassmagal/5051727 to your computer and use it in GitHub Desktop.
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
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