1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| def quick_sort(arr): """快速排序""" if len(arr) < 2: return arr mid = arr[len(arr) // 2] left, right = [], [] arr.remove(mid) for item in arr: if item >= mid: right.append(item) else: left.append(item) return quick_sort(left) + [mid] + quick_sort(right)
|