Python-冒泡排序

 冒泡排序(Python实现)

#利用冒泡排序方法排序

list = [40, 23, 48, 86, 28, 10, 52, 72, 101, 237, 75, 154, 36]
def sortport():
    for i in range(len(list)-1):
        for j in range(len(list)-1-i):
            if list[j] > list[j+1]:
                list[j], list[j+1] = list[j+1], list[j]
    return list

sortport()

#打印输出排序后的列表元素
print(list)
 

 

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