希尔排序(Java实现)

来源:互联网 发布:搜狗微信 php 爬虫 编辑:程序博客网 时间:2024/06/05 17:01

希尔排序:

public class ShellSort {public static void main(String[] args) {int[] a = {23,45,12,78,58,39,66,90,17};shellSort(a);for(int i = 0;i<a.length;i++) {System.out.print(a[i]+" ");}}private static void shellSort(int[] a) {int p = a.length;int i,j;int temp;while(p > 1) {p = p / 2;for( i=p;i<a.length;i=i+p) {temp = a[i];j = i;while(j-p >= 0 && a[j-p] > temp) {a[j] = a[j-p];j = j - p;}a[j] = temp;}}}}