'''完全参考算法导论第三版实现'''
def PARTITION(A,p,r):
x = A[r]
i = p - 1
for j in range(p,r):
if A[j] <= x:
i = i + 1
A[i],A[j] = A[j],A[i]
A[i+1],A[r] = A[r],A[i+1]
return i + 1
def QUICKSORT(A,p,r):
if p < r:
q = PARTITION(A,p,r)
QUICKSORT(A,p,q-1)
QUICKSORT(A,q+1,r)
if __name__ == '__main__':
A = [1,3,8,9,12,7,11,90,34,87,88,56,72,39]
QUICKSORT(A,0,len(A)-1)
print(A)