选择排序

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]

你可能感兴趣的:(选择排序)