a = [4, 6, 2, 1, 8, 3]
for i in xrange(len(a)):
for j in xrange(i+1, len(a)):
if a[i] > a[j]:
tmp = a[i]
a[i] = a[j]
a[j] = tmp
print a # [1, 2, 3, 4, 6, 8]
a = [4, 6, 2, 1, 8, 3]
for i in xrange(len(a)):
for j in xrange(i+1, len(a)):
if a[i] > a[j]:
tmp = a[i]
a[i] = a[j]
a[j] = tmp
print a # [1, 2, 3, 4, 6, 8]
本文标题:选择排序
本文链接:https://www.haomeiwen.com/subject/ytxjbctx.html
网友评论