Skip to content

Instantly share code, notes, and snippets.

@nbenns
Created April 26, 2018 16:10
Show Gist options
  • Save nbenns/0c73e65e104fdfd966a3b7bbded1caca to your computer and use it in GitHub Desktop.
Save nbenns/0c73e65e104fdfd966a3b7bbded1caca to your computer and use it in GitHub Desktop.
import Data.List
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort xs = quicksort lessThanPivot ++ equalToPivot ++ quicksort greaterThanPivot
where
(lessThanPivot, equalToPivot, greaterThanPivot) = epart (head xs) xs
epart :: Ord a => a -> [a] -> ([a], [a], [a])
epart n xs = inner ([], [], []) xs
where
inner a [] = a
inner (l, e, g) (y:ys)
| y < n = inner (y : l, e, g) ys
| y > n = inner (l, e, y : g) ys
| otherwise = inner (l, y : e, g) ys
main :: IO ()
main = do
print $ quicksort [9,5,2,1,4,0,-1,10,100,50,49,124,83,70,21]
print $ quicksort "as;ldjfoiajewo;iqjew;oijwe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment