a_list = [12,13,4,5,1,10,7]
a_low = 0
a_high = 6
def quick_sort(l,low,high):
pivotkey = l[low]
while (low<high):
while (low<high and l[high]>=pivotkey):
high-=1
l[low],l[high] = l[high],l[low]
while (low<high and l[low]<=pivotkey):
low+=1
l[low],l[high] = l[high],l[low]
print low
print l
return low
def q_sort(l,low,high):
if low<high:
pivotloc = quick_sort(l,low,high)
q_sort(l,low,pivotloc-1)
q_sort(l,pivotloc+1,high)
q_sort(a_list,a_low,a_high)
print a_list
网友评论