#-*- coding: UTF-8 -*-
import numpy as np def ShellSort(a):
gap = a.size / 2
while gap >= 1:
for i in xrange(gap,a.size, gap):
for j in xrange(i,0, -gap):
if a[j-gap] > a[j]: a[j-gap] , a[j] = a[j], a[j-gap]
else:
break
gap /= 2 if __name__ == '__main__':
a = np.random.randint(0, 10, size = 10)
print "Before sorting..."
print "---------------------------------------------------------------"
print a
print "---------------------------------------------------------------"
ShellSort(a)
print "After sorting..."
print "---------------------------------------------------------------"
print a
print "---------------------------------------------------------------"
05-23 10:23