冒泡排序

a = [4, 6, 2, 1, 8, 3]

for _ in a:
    for i in xrange(len(a)-1):
        if a[i] > a[i+1]:
            tmp = a[i+1]
            # a[i+1] = a[i]
            # a[i] = tmp
            a[i+1], a[i] = a[i], tmp
print a

你可能感兴趣的:(冒泡排序)