Python- 排序算法-归纳证明算法
2018-03-29 本文已影响0人
老生住长亭
"""
归纳证明算法
"""
def quickSort(array):
if len(array) < 2:
return array
else:
pivot = array[0]
less = [i for i in array[1:] if i <= pivot]
greater = [i for i in array[1:] if i > pivot]
return quickSort(less) + [pivot] + quickSort(greater)
print(quickSort([1, 10, 20, 4, 6, 0, 4, 8, 9,45, 3]))