3 ms·
Ok, I am still learning Haskell, but I thought I would try to fix the above so that there is only one filter pass: qsort :: Ord a => [a] -> [a] qsort [
by hristov 16y ago
Ok, I am still learning Haskell, but I thought I would try to fix the above so that there is only one filter pass:
qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort [x] = [x]
qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater
where
(lesser, greater) = foldl split ([],[]) xs
where
split (left, right) x = if x<p then (left:x, right), else (left, right:x)
Does this work?
- deleted 16y ago[deleted]
- deleted 16y ago[deleted]
- l0stman 16y agoI had to look up what the `:' operator does and it adds an element to the beginning of the list. So the last line should be split (left, right) x = if x<p then (x:left, right), else (left, x:right)