Created
September 8, 2023 22:13
-
-
Save YK-Unit/47e95f40cd338db5a56c4328a1be56ad to your computer and use it in GitHub Desktop.
<以下是使用 Python 实现快速排序的代码: ```python
def quick_sort(arr): if len(arr) <= 1: return arr else: pivot = arr[0] left = [x for x in arr[1:] if x < pivot] right = [x for x in arr[1:] if x >= pivot] return quick_sort(left) + [pivot] + quick_sort(right)
```>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<以下是使用 Python 实现快速排序的代码: | |
```python | |
def quick_sort(arr): | |
if len(arr) <= 1: | |
return arr | |
else: | |
pivot = arr[0] | |
left = [x for x in arr[1:] if x < pivot] | |
right = [x for x in arr[1:] if x >= pivot] | |
return quick_sort(left) + [pivot] + quick_sort(right) | |
```> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment