#!/usr/bin/python3
import random
# 创建无序的列表
def randomList(n):
iList = []
for i in range(n):
iList.append(random.randrange(1000))
return iList
iList = randomList(20)
def selectionSort(iList):
if len(iList) <= 1:
return iList
print(iList)
for i in range(len(iList)):
if iList[i] != min(iList[i:]):
minIndex = iList.index(min(iList[i:]))
iList[i],iList[minIndex] = iList[minIndex],iList[i]
print(iList)
return iList
if __name__ == "__main__":
selectionSort(iList)
网友评论