python常见面试算法

一、冒泡排序

‘‘‘冒泡排序‘‘‘
# coding:utf-8
list = [1, 13, 5, 35, 6, 9, 10]
s = range(len(list))[::-1]
print(s)
for i in s:
for j in range(i):
if list[j] > list[j +1 ]:
list[j], list[j + 1] = list[j + 1], list[j]
print(list)

相关推荐