Ai
1 Star 0 Fork 1

jack2583/PythonExamples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Quick_Sort.py 763 Bytes
一键复制 编辑 原始数据 按行查看 历史
Craig 提交于 2020-10-11 00:33 +08:00 . Merge branch 'master' into patch-1
def partition(arr, low, high):
i = (low - 1)
pivot = arr[high]
for j in range(low, high):
if arr[j] <= pivot:
i = i + 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return (i + 1)
def quickSort(arr, low, high):
if low < high:
pi = partition(arr, low, high)
quickSort(arr, low, pi - 1)
quickSort(arr, pi + 1, high)
arr = [10, 7, 8, 9, 1, 5]
print("Initial array is:", arr)
n = len(arr)
quickSort(arr, 0, n - 1)
patch-1
print("Sorted array is:", arr)
=======
print("Sorted array is:")
patch-4
for i in range(0,n):
=======
for i in range(0,len(arr)):
master
print(arr[i],end=" ")
#your code is best but now it is easy to understand
master
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jack2583/pythonExamples.git
git@gitee.com:jack2583/pythonExamples.git
jack2583
pythonExamples
PythonExamples
master

搜索帮助