1 Star 0 Fork 0

前端代码工具库 / python_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
seacode.py 687 Bytes
一键复制 编辑 原始数据 按行查看 历史
diogoxiang 提交于 2015-11-25 20:16 . 更新一些实例
# coding: UTF-8
# 快速排序
def quickSort(arr):
""" Quicksort a list
:type arr: list
:param arr: List to sort
:returns: list -- Sorted list
"""
if not arr:
return []
pivots = []
lesser = []
greater = []
for x in arr:
if x == arr[0]:
pivots.append(x)
elif x > arr[0]:
greater.append(x)
else:
lesser.append(x)
return quickSort(lesser) + pivots + quickSort(greater)
test_array = [1, 4, 5, 7, 8, 9, 90, 3, 2, 3, 4, 21, 32]
sorted_array = quickSort(test_array)
print(sorted_array)
s1 = 72
s2 = 85
rap = (s2 - s1) / s1
print('%.2f ' % rap)
Python
1
https://gitee.com/tomxiang/python_demo.git
git@gitee.com:tomxiang/python_demo.git
tomxiang
python_demo
python_demo
master

搜索帮助