function quicksort('array')
if length('array') ≤ 1
return 'array' // an array of zero or one elements is already sorted
select and remove a pivot element 'pivot' from 'array'
// see 'Choice of pivot' below
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'), list('pivot'), quicksort('greater'))
// two recursive calls
def quicksort(array):
less = []; greater = []
if len(array) <= 1:
return array
pivot = array.pop()
for x in array:
if x <= pivot: less.append(x)
else: greater.append(x)