import random
def quickSort(array):
if len(array) < 2:
return array
else:
pivot = array[0]
smaller = [item for item in array[1:] if item <= pivot]
bigger = [item for item in array[1:] if item > pivot]
return quickSort(smaller) + [pivot] + quickSort(bigger)
array = random.sample(range(100), 4)
print array
print quickSort(array)
快速排序算法的Python实现
最新推荐文章于 2024-09-02 13:48:37 发布