我在python中键入快捷排序,但无法找出为什么该分区功能不起作用。
def partition(arr,low, high):
i=low
for counter in range(low, high):
if arr[counter]<arr[i]:
s=arr[counter]
del arr[counter]
arr=[s,]+arr
i+=1
print(arr,i,counter)
return i
arr=[10,11,6,3,5,7,8]
n=len(arr)
partition(arr,0,n)
print(arr)
输出:
[10, 11, 6, 3, 5, 7, 8] 0 0
[10, 11, 6, 3, 5, 7, 8] 0 1
[6, 10, 11, 3, 5, 7, 8] 1 2
[3, 6, 10, 11, 5, 7, 8] 2 3
[5, 3, 6, 10, 11, 7, 8] 3 4
[7, 5, 3, 6, 10, 11, 8] 4 5
[8, 7, 5, 3, 6, 10, 11] 5 6
[10, 11, 3, 5, 7, 8]