-6
代碼鏈接在這裏:http://ideone.com/eba7CB
我似乎無法找到該錯誤。任何幫助和批評都表示讚賞。
QuickSort實施中的錯誤
ar = []
def quick(l, r):
if (r-l) <= 1:
return
pivot = ar[l]
i = l+1
for j in range(l+1,r):
if ar[j] < pivot:
ar[i],ar[j] = ar[j],ar[i]
i+=1
ar[i-1],ar[l] = ar[l],ar[i-1]
# print i,j
quick(l,i)
quick(i+1,r)
def qSort():
l = 0
r = len(ar)
quick(l,r)
ar = [4, 2, 13, 10, 7, 3]
qSort()
print ar
的輸出是[2,3,4,10,7,13]