12345678910111213141516 |
- algorithm quicksort(A, lo, hi) is
- if lo < hi then
- p := partition(A, lo, hi)
- quicksort(A, lo, p – 1)
- quicksort(A, p + 1, hi)
- algorithm partition(A, lo, hi) is
- pivot := A[hi]
- i := lo - 1
- for j := lo to hi - 1 do
- if A[j] ≤ pivot then
- i := i + 1
- swap A[i] with A[j]
- swap A[i+1] with A[hi]
- return i + 1
- Sorting the entire array is accomplished by quicksort(A, 1, length(A)).
|