1 if __name__ == '__main__': 2 ''' 3 选择排序 4 1.初始状态:无序区为R[1...n],有序区为空 5 2.第i趟排序(i = 1,2,3...n-1)开始时,当前有序列区和无序区分别为R[1...i-1]和R[i...n]。该次排序从当前无序区中选取最小值记录下来 6 将它与无序区第一个值交换位置,然后使有序区和无序区下边加1即有序区R[1...i],无序区R[i+1...n] 7 3.n-1此结束排序 8 ''' 9 arr = [1, 23, 45, 76, 12, 3, 565, 87, 123, 786, 1312, 76, 34, 2, 32, 54, 7] 10 var = len(arr) 11 for i in range(var - 1): 12 minIndex = i 13 for j in range(i + 1, var): 14 if arr[j] < arr[minIndex]: 15 minIndex = j 16 17 temp = arr[i] 18 arr[i] = arr[minIndex] 19 arr[minIndex] = temp 20 print(arr)
标签:minIndex,...,arr,无序,选择,__,排序 From: https://www.cnblogs.com/400-500/p/18639432