python 小练习之冒泡排序
冒泡排序:多重循环
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
def bubbleSort(numbers):
for j in range(len(numbers)-1, -1, -1):
for i in range(j):
if numbers[i] > numbers[i + 1]:
numbers[i], numbers[i + 1] = numbers[i + 1], numbers[i]
#print numbers #输出过程
numbers = [23, 21, 52, 22, 19]
bubbleSort(numbers)
print numbers #只输出结果
相关文章