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 "---------------------------------------------------------------"