选择排序
2020-12-13 04:05
标签:index selection pop 图解 select -- color war turn -- 转自 算法图解 选择排序 标签:index selection pop 图解 select -- color war turn 原文地址:https://www.cnblogs.com/yixiu868/p/11104076.htmldef findSmallest(arr):
smallest = arr[0]
smallest_index = 0
for i in range(1, len(arr)):
if arr[i] smallest:
smallest = arr[i]
smallest_index = i
return smallest_index
def selectionSort(arr):
newArr = []
for i in range(len(arr)):
smallest = findSmallest(arr)
newArr.append(arr.pop(smallest))
return newArr
上一篇:JSP/Servlet基础语法
下一篇:spring bean