function quicksort('array')
if length('array') ≤ 1
return 'array' // an array of zero or
//one elements is already sorted
select and remove a pivot value 'pivot' from 'array'
create empty lists 'less' and 'greater'
for each 'x' in 'array'
if 'x' ≤ 'pivot' then append 'x' to 'less'
else append 'x' to 'greater'
return concatenate(quicksort('less'), 'pivot',
quicksort('greater')) // two recursive calls
Here is an Image depicting Quick Sort:
|
In-place partition in action on a small list.
The boxed element is the pivot element,
blue elements are less or equal, and red
elements are larger. |