python写冒泡排序
#冒泡排序
def mbpx(List):
n = len(List)
for i in range(n):
for j in range(0,n-i-1):
if List[j]>List[j+1]:
temp = List[j+1]
List[j+1] = List[j]
List[j] = temp
# List[j+1], List[j] = List[j] , List[j+1]
s = [1, 7, 4, 12, 3, 6, 98, 34]
mbpx(s)
print(s)
运行结果: