又称缩小增量排序:
function shellSort(array) { var j, i, v, h=1, s=3, k,n = array.length while(h < n) h=s*h+1; while(h > 1) { h=(h-1)/s; for (k=0; k<h; k++) for (i=k+h,j=i; i<n; i+=h, j=i) { v=array[i]; while(true) if ((j-=h) >= 0 && array[j] > v) array[j+h]=array[j]; else break; array[j+h]=v; } } }
排序过程如【动画模拟演示】。