您的位置:首页 > 其它

selection sort DEMO(linear complexity)

2015-07-09 08:46 225 查看
#quote from MIT 'introduction to computation and programming using python, Revised'
def selSort(L):
"""Assumes that L is a list of elements that can be
compared using >.
Sorts L in ascending order"""
suffixStart = 0
while suffixStart != len(L):
#look at each element in suffix
for i in range(suffixStart, len(L)):
if L[i] < L[suffixStart]:
#swap position of elements
L[suffixStart], L[i] = L[i], L[suffixStart]
suffixStart += 1


L = [1, 10, 2, 9, 7, 100, 99, 23, 0]

selSort(L)

print L

[0, 1, 2, 7, 9, 10, 23, 99, 100]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: