快速排序
描述:数组A[p...r] 分成两个子数组 A[p...q-1] 和 A[q+1...r], 使得A[p...q-1]里面的所有元素都小于等于A[q], A[q+1...r]里的所有元素都大于等于A[q], 然后对两个子数组递归调用快速排序。
QUICKSORT(A, p, r)
if(p[InvalidCharacterError: "R)<" did not match the Name production]
PARTITION(A, p, r)
x=A[r]
i=p-1
for j=p to r-1
if A[j]<=x
i = i+1
exchange A[i] with A[j]
exchange A[i+1] with A[r]
return i+1
总是会选择一个x=A[r] 作为主元,并围绕它来划分子数组。