問題描述:
將一組無序的元素序列按照規則得到其有序序列。每次選擇未排序序列中最小的元素。
要求:
1. 按提示完成程式
2. 輸出選擇排序花費的時間
程式模板如下,請完成TODO部分。
########################
# 找出當前序列中最小的元素
def findSmallest(list):
//TODO:用smallest存放當前序列中的最小元素
//TODO:初始化最小元素的索引即存放位置
for i in range(1, len(list)):
if list[i] < smallest:
//TODO:更新當前序列的最小元素,更新索引值
return smallest_index
# 對序列進行排序
def selectionSort(list):
newlist = []
for i in range(len(list)):
# Finds the smallest element in the array and adds it to the new array
//TODO:找到當前串列中的最小元素,并將其添加至newlist中
return newlist
#測驗陳述句
print(selectionSort([5, 3, 6, 2, 10]))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/111594.html
標籤:C語言
上一篇:fprintf報錯
