qsort li
| null li = []
| otherwise = qsort lt ++ [p] ++ qsort gt
where
(p:xs) = li
lt = [x | x <- xs, x <= p]
gt = [x | x <- xs, x > p]
qsort0 [] = []
qsort0 (p:xs) = qsort0 lt ++ [p] ++ qsort0 gt
where
lt = [x | x <- xs, x <= p]
gt = [x | x <- xs, x > p]
qsort1 li =
if null li then []
else let
(p:xs) = li
lt = [x | x <- xs, x <= p]
gt = [x | x <- xs, x > p]
in qsort1 lt ++ [p] ++ qsort1 gt
qsort2 li =
if null li then []
else qsort2 lt ++ [p] ++ qsort2 gt
where
(p:xs) = li
lt = [x | x <- xs, x <= p]
gt = [x | x <- xs, x > p]
qsort4 li =
case li of
[] -> []
(p:xs) -> qsort4 lt ++ [p] ++ qsort4 gt
where
lt = [x | x <- xs, x <= p]
gt = [x | x <- xs, x > p]
main = putStrLn $ show $ qsort [5,1,4,2,3]
To embed this project on your website, copy the following code and paste it into your website's HTML: