Python進階-演算法-插入排序

娜娜0130發表於2018-08-26
版權宣告:如需轉載,請註明轉載地址。 https://blog.csdn.net/oJohnny123/article/details/82085568
data_set = [ 9,1,22,9,31,-5,45,3,6,2,11 ]
loop = 0
for i in range(len(data_set)):
    while i > 0 and data_set[i] < data_set[i-1]:# 右邊小於左邊相鄰的值
        tmp = data_set[i]
        data_set[i] = data_set[i-1]
        data_set[i-1] = tmp
        i -= 1

        

print(data_set)

 


相關文章