Created
April 26, 2018 16:10
-
-
Save nbenns/0c73e65e104fdfd966a3b7bbded1caca to your computer and use it in GitHub Desktop.
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.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