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