您的位置:首页 > 其它

希尔排序

2015-06-17 17:28 288 查看
package sort;

public class ShellSort1 {

public static void ShellSort(int array[]){
int gap,i,j;
for(gap = array.length / 2;gap > 0;gap /= 2){
for(i = gap;i < array.length;i++ ){
int temp = array[i];
for(j = i - gap; j >= 0 && array[j] > temp;j -= gap)
array[j + gap] = array[j];
array[j + gap] = temp;
}
}
}

public static void main(String[] args) {
int array[] = {19, 17, 16, 12, 9, 15, 1, 2, 11, 7, 3, 10, 14, 0, 344, 22, 43, 111};
ShellSort(array);
for(int k = 0;k < array.length;k++)
System.out.print(array[k]+" ");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  希尔排序