打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
冒泡,选择,快速 排序-Python实现
1.选择
>>> def choice(l):
a=len(l)
for i in range(a):
maxx=i
for j in range(i+1,a):
if l[j]>l[maxx]:
maxx=j
if maxx!=i:
l[i],l[maxx]=l[maxx],l[i]
print l

2.冒泡排序
>>> def bubble(l):
for i in range(len(l)):
for j in range(len(l)-i-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]
print l

3.快排
def quickSort(a,low,high):
if low<high:
i=low
j=high
temp=a[low]
while i<j:
while a[j]>temp and i<j:
j-=1
if i<j:
a[i]=a[j]
i+=1
while a[i]<temp and i<j:
i+=1
if i<j:
a[j]=a[i]
j-=1
a[i]=temp
quickSort(a,low,i-1)
quickSort(a,i+1,high)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
持续输出Java面试题之交换排序
python四种排序方法详解
作业:三个排序法时间比较
插入,冒泡,选择,快速排序,二分查找
用VC++类实现快速排序(并输出过程)
几种排序算法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服