Quicksort is not a stable sort. Which means that Objects that are equal can have their order changed within the sorted list.
Input: a list of values, arr.
quicksort(arr) initialize list ''less'' initialize list ''greater'' if arr.count ≤ 1 return arr pivot = select a pivot value from arr remove pivot from arr for each x in arr if x < pivot then add x to less else add x to greater return concatenate quicksort(less), pivot, quicksort(greater)
One way to select the pivot is to get the middle value. The following pseudocode works for zero-based indices:
pivot = arr at arr.count / 2 // integer division
- the Java Arrays class uses a modified quicksort for the sort method on arrays of primitive types.
- In .NET quicksort is used for both lists and arrays by the sort method.