Sorting algorithms/Quicksort: Difference between revisions

Content deleted Content added
Line 1,631: Line 1,631:


The famous two-liner, reflecting the underlying algorithm directly:
The famous two-liner, reflecting the underlying algorithm directly:
<lang haskell>qsort [] = []
<lang haskell>qsort [] = []
qsort (x:xs) = qsort [y | y <- xs, y < x] ++ [x] ++ qsort [y | y <- xs, y >= x]</lang>
qsort (x:xs) = qsort [y | y <- xs, y < x] ++ [x] ++ qsort [y | y <- xs, y >= x]</lang>
A more efficient version, doing only one comparison per element:
A more efficient version, doing only one comparison per element: