//shell排序配插入排序function shell_insert_sort(arr){ var gap = arr.length; do{ gap = parseInt(gap/3) + 1; console.log(gap); for(var i = gap; i < arr.length; i+= gap){ var tmp = arr[i]; for( var j = i - gap; j >= 0 && tmp < arr[j]; j -= gap){ ar
今天看<The C Programming Language>的时候看到了shell排序算法, /* shellsort: sort v[0]...v[n-1] into increasing order */ void shellsort(int v[], int n) { int gap, i, j, temp; ; gap > ; gap /= ) for (i = gap; i < n; i++) && v[j]>v[j+gap]; j-=gap) {
# coding=utf-8 # shell排序 # 参数alist:被被排序的列表 def shellsort(alist): gap = len(alist) / 2 while gap > 0: for i in range(gap): shellinsert(alist, i, gap) gap = gap / 2 print alist #根据步长进行插入排序 def shellinsert(alist, start, gap): for i in range(start + gap,