本文共 365 字,大约阅读时间需要 1 分钟。
#简单选择排序
def selectionSort(arr):for i in range(0, len(arr)-1):minidx = i # 找到最小数 for j in range(i+1, len(arr)): if arr[minidx] > arr[j]: minidx = j # 将最小数排到前面的位置 temp = arr[minidx] arr[minidx] = arr[i] arr[i] = temp print(arr)
arr = [5,4,3,2,1]
selectionSort(arr)转载于:https://blog.51cto.com/10440592/2046105