氣泡排序(python版)

文盲青年發表於2020-11-03
import random

attr = [3, 2, 5, 8, 6, 9, 9, 13, 11, 6]
# attr = [random.randint(1, 10) for x in range(0, 10)]

print(attr)
for i in range(len(attr) - 1):
    for j in range(len(attr) - 1 - i):
        if attr[j] > attr[j + 1]:
            attr[j], attr[j + 1] = attr[j + 1], attr[j]

print(attr)

相關文章