希尔排序算法-python实现

 #-*- 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 "---------------------------------------------------------------"
上一篇:asp.net oracle 存储过程


下一篇:JAVA NIO工作原理及代码示例