快速排序
# -*- coding: UTF-8 -*-
def quick_sort(arr):
if(len(arr) < 2):
return arr
else:
base = arr[0]
less = [i for i in arr[1:] if i <= base]
great = [i for i in arr[1:] if i > base]
return quick_sort(less) + [base] + quick_sort(great)
if(__name__ == "__main__"):
arr = [1, 3, 5, 4, 8, 7, 34, 22, 15]
sorted_arr = quick_sort(arr)
for i in sorted_arr:
print(i)