快速排序算法代码python
时间: 2023-12-01 16:42:09 浏览: 117
以下是快速排序算法的Python代码实现:
```python
def quick_sort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quick_sort(right)
```
阅读全文