1. 程式人生 > >python實現選擇演算法

python實現選擇演算法

// python實現選擇排序
# 定義選擇最大值的函式
def selectionSortFunction(list):
    newlist=[]
    for i in range(len(lsit)):
        maxOne = max(list)
        newlist.append(maxOne)
        list.remove(one)
    return newlist
print(selectionSortFunction(([1,3,0,23,14,25,53,27]))
#輸出
[53, 27, 25, 23, 14, 3, 1, 0]