快速排序算法伪代码
//快速排序
QUICK_SORT(A, p, q)
{
if p < q
pivot = PARTITION(A, p, q) //基数
QUICK_SORT(A, p, pivot-1)
QUICK_SORT(A, pivot+1, q)
}
PARTITION(A, p ,q)
{
left = p
right = q
temp = A[left]
while left < right
while left < right && A[right] >= temp
--right;
if left < right
swap A[left] <-> A[right]
while left < right && A[left] <= temp
++left
if left < right
swap A[right] <-> A[left]
A[left] = temp
return left
}
用快速排序算法对数组arr[10] = {8, 5, 10, 12, 7, 6, 15, 9, 11, 3}从小到大排序。