1 Star 0 Fork 1

王其/托管

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
快速排序.py 772 Bytes
Copy Edit Raw Blame History
王其 authored 2021-10-26 16:54 +08:00 . add 快速排序.py.
#coding=utf-8
def quick_sort(data):
if len(data) >= 2: # 递归入口及出口
mid = data[len(data)//2] # 选取基准值,也可以选取第一个或最后一个元素
left, right = [], [] # 定义基准值左右两侧的列表
data.remove(mid) # 从原始数组中移除基准值
for num in data:
if num >= mid:
right.append(num)
else:
left.append(num)
return quick_sort(left) + [mid] + quick_sort(right)
else:
return data
array = [3,7,1,4,6,15,5,2,10,9,17,12]
print("排序后的数组:")
print(quick_sort(array))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wang-qi3206/trusteeship.git
git@gitee.com:wang-qi3206/trusteeship.git
wang-qi3206
trusteeship
托管
master

Search