Created
May 5, 2012 08:37
-
-
Save jprupp/2600974 to your computer and use it in GitHub Desktop.
Haskell Quicksort
This file contains 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
split :: Ord a => a -> [a] -> ([a],[a]) | |
split x ys = accum x ys ([],[]) | |
where | |
accum :: Ord a => a -> [a] -> ([a],[a]) -> ([a],[a]) | |
accum _ [] result = result | |
accum x (y:ys) (ls,rs) | |
| y > x = accum x ys (ls,y:rs) | |
| otherwise = accum x ys (y:ls,rs) | |
sort :: Ord a => [a] -> [a] | |
sort [] = [] | |
sort (x:xs) = sort l ++ [x] ++ sort r | |
where (l,r) = split x xs | |
main = print (sort [3,6,12,4,1,2,8,10,9,7,5,11]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had fun writing this little quicksort implementation in Haskell this morning. What a geek!