def exch(l,i,j):
temp = l[i]
l[i] = l[j]
l[j] = temp
def sort(l):
quick(l,0,len(l) - 1)
def quick(l,lo,hi):
if lo >= hi: return
v = l[0]
i = lo
gt = hi
lt = lo
while i <= gt:
cmp = l[i] - v
if cmp == 0 : i+=1
if cmp < 0 :
exch(l,i,lt)
i += 1
lt +=1
if cmp > 0 :
exch(l,i,gt)
gt -= 1
quick(l,lo,lt -1)
quick(l,gt + 1,hi)
l = [9,9,8,8,7,6,7,5,4,3,2,5,2,1,4,5,7,8,3,4,6]
sort(l)
print l
三路快排 duplicate keys
最新推荐文章于 2024-09-05 10:48:18 发布