public class ShellSort {
public static void shellSort(Comparable[] data){
int j;
for(int gap = data.length / 2; gap > 0; gap /= 2){
for(int i = gap; i < data.length; i ++){
Comparable tmp = data[i];
for(j = i; j >= gap && tmp.compareTo(data[j - gap]) < 0; j -= gap)
data[j] = data[j - gap];
data[j] = tmp;
}
}
}
public static void main(String[] args){
Comparable[] a = {13,25,1,2,3,4,6,9,25,9787,25,64,32,11,18,72,23,7};
shellSort(a);
for(int i = 0; i < a.length; i ++)
System.out.print(a[i]+ ",");
}
}
ShellSort 希尔排序算法
最新推荐文章于 2024-08-24 23:00:16 发布