# 升序 defselect_sort(data): n = len(data) # 外循环,i 代表扫描轮数,一共扫描 n-1 轮 for i in range(n-1): min_idx = i # 内循环,从未排序数据中找出最小数 for j in range(i+1, n): if data[min_idx]>data[j]: min_idx=j if min_idx!=i: data[min_idx], data[i] = data[i], data[min_idx] return data
if __name__ == '__main__': data = [64, 25, 12, 22, 11] sorted_data = select_sort(data.copy()) print("排序前:", data) print("排序后:", sorted_data)