Python排序算法
时间:2020-08-17 17:55:44
收藏:0
阅读:98
1、简单选择排序
1 def selectionSort(lyst): 2 i = 0 3 while i < len(lyst) - 1: 4 minIndex = i 5 j = i + 1 6 while j < len(lyst): 7 if lyst[j] < lyst[minIndex]: 8 minIndex = j 9 j += 1 10 if minIndex != i: 11 lyst[minIndex], lyst[i] = lyst[i], lyst[minIndex] 12 i += 1 13 return lyst 14 15 if __name__ == "__main__": 16 list = [5,6,1,3,89,23,56,15,95] 17 result = selectionSort(list) 18 print(result)
评论(0)