时间复杂度:O(n^2)
def 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
print (selectionSort([5, 3, 6, 3, 33, 2, 66, 8]))