by ola · 18y ago · 0 comments
quicksort (x:xs) = let (a, b) = span (< x) xs in (quicksort a) ++ [x] ++ (quicksort b) quicksort (x:xs) = let (a, b) = span (< x) xs in (quicksort a) ++ [x] ++ (quicksort b)
Actually, this is incorrect. span will split the list as soon as it finds the predicate to be false on an item, instead of finding the smaller elements of the whole list. So, for instance, if we try your function as in the following, we get improper results: > quicksort [1, 2, 3, 2, 1]
[1,2,1,2,3]
> quicksort [1, 2, 3, -2, -1]
[1,2,-2,-1,3]
> quicksort [1, 2, 3, -2, 0, -1]
[1,2,-2,-1,0,3]