Python快排

1 def quick_sort(arr):
2     if len(arr) <= 1:
3         return arr
4     else:
5         base = arr[0]
6         less = [v for v in arr[1:] if v<=base]
7         more = [v for v in arr[1:] if v>base]
8         return quick_sort(less) + [base] + quick_sort(more)

 

def quick_sort(arr):if len(arr) <= 1: return arr else: base = arr[0] less = [v for v in arr[1:] if v<=base] more = [v for v in arr[1:] if v>base] return quick_sort(less) + [base] + quick_sort(more)

posted @ 2020-04-23 12:03  燕十三丶  阅读(234)  评论(0编辑  收藏  举报
AmazingCounters.com