def quickSort(a,left,right):
if left < right:
i = left
j = right
key = a[left]
while i < j:
while i<j and a[j]>=key:
j-=1
a[i] = a[j]
print(a,i,j)
while i<j and a[i]<=key:
i+=1
a[j] = a[i]
print(a,i,j)
a[i]=key
quickSort(a,left,i-1)
quickSort(a,i+1,right)
if name == 'main':
A = [5,-4,6,3,7,11,1,2]
print(A)
quickSort(A, 0, 7)
print('After sort:',A)
网友评论