首页 > 代码库 > ShellSort

ShellSort

code:

 1 @SuppressWarnings({ "rawtypes", "unchecked" }) 2 public static void shellSort(Object[] array) { 3     int len = array.length; 4     int h = 1; 5     while (h <= len / 3) 6         h = h * 3 + 1; 7     while (h > 0) { 8         for (int i = h; i < len; i++) { 9             Comparable tmp = (Comparable) array[i];10             int j = i;11             while (j >= h && tmp.compareTo(array[j - h]) < 0) {12                 array[j] = array[j - h];13                 j -= h;14             }15             array[j] = tmp;16         }17         h = (h - 1) / 3;18     }19 }

 

ShellSort