您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 内江分类信息网,免费分类信息发布

python选择排序算法实例总结

2025/7/1 5:21:53发布6次查看
本文实例总结了python选择排序算法。分享给大家供大家参考。具体如下:
代码1:
def ssort(v):#v is the list to be sorted j = 0 #j is the current ordered position, starting with the first one in the list while j != len(v): #this is the replacing that ends when it reaches the end of the list for i in range(j, len(v)): #here it replaces the minor value that it finds with j position if v[i] < v[j]: #but it does it for every value minor than position j v[j],v[i] = v[i],v[j] j = j+1 #and here's the addiction that limits the verification to only the next values return v
代码2:
def selection_sort(list): l=list[:] # create a copy of the list sorted=[] # this new list will hold the results while len(l): # while there are elements to sort... lowest=l[0] # create a variable to identify lowest for x in l: # and check every item in the list... if xl[j]: # to compare two values which store in num and list index=j # to store the small value of the loop j in index num=l[j] # to store small charecter are value in num tem=l[i] # to swap the list take the temparary list stor list vlaues l[i]=l[index] # to take first value as another l[index]=tem print after the swping the list by selection sort is,l
希望本文所述对大家的python程序设计有所帮助。
内江分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product