Created
October 27, 2011 09:31
-
-
Save klapaucius/1319163 to your computer and use it in GitHub Desktop.
in-place quick sort
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
import Data.Vector.Generic | |
import qualified Data.Vector.Generic.Mutable as M | |
iqsort :: (Vector v a, Ord a) => v a -> v a | |
iqsort = modify go where | |
go xs | len < 2 = return () | |
| otherwise = do | |
p <- xs `M.read` (len `div` 2) | |
m <- M.unstablePartition (< p) xs | |
go $ M.slice 0 m xs | |
go $ M.slice (m+1) (len-m-1) xs | |
where len = M.length xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment