Skip to main content

quicksort

Function quicksort 

Source
pub fn quicksort<T: Ord>(slice: &mut [T])
Expand description

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.