public class ShellSortJava {
public static void main(String[] args) {
int[] aa = { 49, 38, 65, 97, 76, 13, 27 };
int[] result = new ShellSort().shellSort(aa);
for (int s : result) {
System.out.println(s);
}
}
}
class ShellSort {
int[] shellSort(int[] a) {
int j;
for (int gap = a.length / 2; gap > 0; gap /= 2) {
for (int i = gap; i < a.length; i++) {
int tmp = a[i];
for (j = i; j >= gap && tmp < a[j - gap]; j -= gap) {
a[j] = a[j - gap];
}
a[j] = tmp;
}
}
return a;
}
}
Java 希尔排序
最新推荐文章于 2024-11-07 13:06:59 发布