python数据结构之冒泡排序
#-*-coding:utf-8-*-
'''
冒泡排序:
冒泡排序就是两次循环
'''
def BubbleSort(L):
length = len(L)
for i in range(0,length):
for j in range(i+1,length):
if L[i] > L[j]:
L[i], L[j] = L[j], L[i]
return L
L = [5,4,2,3,6,1,0]
print("原始序列:")
print(L)
print("冒泡排序:")
print(BubbleSort(L))
程序输出结果:
原始序列:
[5, 4, 2, 3, 6, 1, 0]
冒泡排序:
[0, 1, 2, 3, 4, 5, 6]