Skip to content

Instantly share code, notes, and snippets.

@christopher-beckham
Created April 6, 2014 09:04
Show Gist options
  • Save christopher-beckham/10003377 to your computer and use it in GitHub Desktop.
Save christopher-beckham/10003377 to your computer and use it in GitHub Desktop.
quicksort :: [Int] -> [Int]
quicksort [] = []
quicksort [x] = [x]
quicksort xs =
quicksort(less) ++ [pivot] ++ quicksort(greater)
where
m = length xs `div` 2
pivot = xs!!m
less = [ xs!!i | i <- [0..(length xs)-1], xs!!i <= pivot && i /= m ]
greater = [ xs!!i | i <- [0..(length xs)-1], xs!!i > pivot && i /= m ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment