国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗 > 正文

pytho!n選擇排序算法實例總結

2019-11-02 14:37:04
字體:
供稿:網(wǎng)友

   本文實例總結了python選擇排序算法。分享給大家供大家參考。具體如下:

  代碼1:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 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:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 x<lowest: # to see if it might be lower. lowest=x sorted.append(lowest) # add the lowest one to the new list l.remove(lowest) # and delete it from the old one return sorted

  代碼3

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 a=input("Enter the length of the list :") # too ask the user length of the list l=[] # take a emty list for g in range (a): # for append the values from user b=input("Enter the element :") # to ask the user to give list values l.append(b) # to append a values in a empty list l print "The given eliments list is",l for i in range (len(l)): # to repeat the loop take length of l index=i # to store the values i in string index num=l[i] # to take first value in list and store in num for j in range(i+1,len(l)): # to find out the small value in a list read all values if num>l[j]: #
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 祁阳县| 金沙县| 甘谷县| 郸城县| 夏河县| 武川县| 来宾市| 沂源县| 望都县| 炉霍县| 大渡口区| 荣成市| 陈巴尔虎旗| 苍梧县| 曲麻莱县| 永福县| 昔阳县| 赣州市| 汝州市| 五大连池市| 北宁市| 东阿县| 黔东| 虞城县| 永福县| 雷波县| 湾仔区| 永修县| 惠州市| 石景山区| 麻栗坡县| 张家川| 襄垣县| 广平县| 海淀区| 田阳县| 怀安县| 怀远县| 东方市| 聊城市| 乌苏市|