寫一個(gè)python 選擇排序:
def selection_sort(list):
for fill_slot in range(0, len(list) - 1, 1):
print(fill_slot)
index = fill_slot
for location in range(fill_slot + 1, len(list), 1):
if list[location] > list[index]:
index = location
list[fill_slot], list[index] = list[index], list[fill_slot]
if __name__ == '__main__':
a_list = [54, 26, 93, 17, 77, 31, 44, 55, 20]
selection_sort(a_list)
print(a_list)
range(start, end, step) 產(chǎn)生一個(gè)可以迭代的對(duì)象昌罩。