Skip to main content

Module quicksort

Module quicksort 

Source
Expand description

Quicksort.

See the book entry Comparison sorting.

Functions§

quicksort
Sorts a slice using quicksort: a median-of-three pivot, Hoare’s partition (whose two scans both stop at keys equal to the pivot, so runs of equal keys are split evenly rather than piling up on one side), insertion sort for ranges of 16 or fewer, and recursion on the smaller side so the stack depth is O(log n). As in Musser’s introsort, a range still unsorted after 2 log₂ n partitions is finished by heapsort, so the worst case is O(n log n) even on inputs built to defeat median-of-three.