‘‘‘选择排序, 找到最大或最小的,放一边,然后继续找‘‘‘ import time start = time.time() def selectionSort(alist): for i in range(len(alist)-1): min_index = i for j in range(i+1,len(alist)): if alist[min_index]> alist[j]: min_index = j # 先调换index,然后在循环外面调换具体数值 alist[i], alist[min_index] = alist[min_index], alist[i] if __name__ ==‘__main__‘: alist =[10,9,8,7,6,5,4,3,2,1] selectionSort(alist) print(alist) end = time.time() print(end-start)
时间: 2024-11-08 23:50:22