Python 冒泡排序

 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 data = [10,4,33,21,54,3,8,11,5,22,2,1,17,13,6]
 4 
 5 for j in range(1,len(data)):
 6     for i in range(len(data)-j):
 7         if data[i] > data[i+1]:
 8             tmp = data[i+1]
 9             data[i+1] = data[i]
10             data[i] = tmp
11 print(data)

[1, 2, 3, 4, 5, 6, 8, 10, 11, 13, 17, 21, 22, 33, 54]
posted @ 2018-07-26 21:36  Presley  阅读(165)  评论(0编辑  收藏  举报