美文网首页
快速排序Python

快速排序Python

作者: 水平 | 来源:发表于2016-11-15 17:34 被阅读29次

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)

相关文章

网友评论

      本文标题:快速排序Python

      本文链接:https://www.haomeiwen.com/subject/jtllpttx.html