function quicksort(q) var list less, pivotList, greater if length(q) = 1 { return q } else { select a pivot value pivot from q for each x in q except the pivot element if x < pivot then add x to less if x = pivot then add x to greater add pivot to pivotList return concatenate(quicksort(less), pivotList, quicksort(greater)) }