- Open src/Main.hs and write the qsort implementation. The qsort involves the following:
- Choosing an element of the list to be sorted
- Using the chosen element as a pivot, divide the input list into two parts:
- Subset of the list smaller than the pivot element
- Subset of the list greater than or equal to the pivot element
- Recursively sorting two parts in a similar way
- In Haskell, we can implement a method like quick sort quite easily. Ord a in the qsort declaration signifies that the elements of the list [a] can be compared for inequality, and it is possible to use the operators <, >, <=, and >=:
qsort :: Ord a => [a] -> [a] qsort [] = [] qsort (x:xs) = qsort ys ++ [x] ++ qsort zs where ys = filter (\y -> y < x) xs zs ...