1 #-*- coding: UTF-8 -*- 2 import numpy as np 3 4 def InsertSort(a): 5 for i in xrange(1,a.size): 6 for j in xrange(i,0, -1): 7 if a[j-1] > a[j]: 8 a[j-1] , a[j] = a[j], a[j-1] 9 else: 10 break 11 12 if __name__ == '__main__': 13 a = np.random.randint(0, 10, size = 10) 14 print "Before sorting..." 15 print "---------------------------------------------------------------" 16 print a 17 print "---------------------------------------------------------------" 18 print "After sorting..." 19 InsertSort(a) 20 print "---------------------------------------------------------------" 21 print a 22 print "---------------------------------------------------------------"