很多基础的算法只看不写很容易忽略其中的细节,对于既不浪费空间又可以快一点的快速排序算法,用python重新实现了一遍,下面具体的实现方法,仅供参考。
def quicksort(left,right):
if left>right:
return
temp=a[left]
i=left
j=right
while i!=j:
while a[j]>=temp and i<j:
j=j-1
print(a[j])
while a[i]<=temp and i<j:
i=i+1
if i<j:
t=a[i]
a[i]=a[j]
a[j]=t
a[left]=a[i]
a[i]=temp
quicksort(left,i-1)
quicksort(i+1,right)