python的算法简要到你可以见性直指:
def q_sort(l):
if len(l)<=1:
return l
else:
p=l[0]
small_part=[x for x in l[1:] if x<p]
big_part=[x for x in l[1:] if x>=p]
return q_sort(small_part)+[p]+q_sort(big_part)
太好理解了吧!这就是算法的精要?
还有更简单的,
def q_sort(l):
if len(l)<=1:
return l
else:
return q_sort([x for x in l[1:] if x<l[0]])+[l[0]]+q_sort([x for x in l[1:] if x>=l[0]])