Skip to content

Instantly share code, notes, and snippets.

@jprupp
Created May 5, 2012 08:37
Show Gist options
  • Save jprupp/2600974 to your computer and use it in GitHub Desktop.
Save jprupp/2600974 to your computer and use it in GitHub Desktop.
Haskell Quicksort
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])
@jprupp
Copy link
Author

jprupp commented May 5, 2012

I had fun writing this little quicksort implementation in Haskell this morning. What a geek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment