冒泡排序算法-Python实现
1 #-*- coding: UTF-8 -*- 2 import numpy as np 3 def BubbleSort(a): 4 for i in xrange(0, a.size): 5 for j in xrange(i,a.size): 6 if a[j] < a[i]: 7 a[i], a[j] = a[j], a[i] 8 9 if __name__ == '__main__': 10 a = np.random.randint(0, 10, size = 10) 11 print "Before sorting..." 12 print "---------------------------------------------------------------" 13 print a 14 print "---------------------------------------------------------------" 15 BubbleSort(a) 16 print "After sorting..." 17 print "---------------------------------------------------------------" 18 print a 19 print "---------------------------------------------------------------"
作者:Alex Yu
出处:http://www.cnblogs.com/biaoyu/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。