代码链接在这里:http://ideone.com/eba7CB我似乎无法找到错误。任何帮助和批评都表示赞赏。
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]
答案 0 :(得分:0)
替换 快速第(i + 1,r)的 通过: 快(I,R)