Quicksort


Quicksort

A sorting algorithm with O(n log n) average timecomplexity.

One element, x of the list to be sorted is chosen and theother elements are split into those elements less than x andthose greater than or equal to x. These two lists are thensorted recursively using the same algorithm until there isonly one element in each list, at which point the sublists arerecursively recombined in order yielding the sorted list.

This can be written in Haskell:

qsort :: Ord a => [a] -> [a]qsort [] = []qsort (x:xs) = qsort [ u | u=x ]

[Mark Jones, Gofer prelude.]