package java面试宝典; import java.util.Arrays; public class 希尔排序 { public static void main(String[] args) { int[] a={6,9,3,5,7,1,8,0,2,4}; System.out.println(Arrays.toString(a)); shellSort(a); System.out.println(Arrays.toString(a)); } public static void shellSort(int[] a){ for (int h = a.length/2; h >0; h/=2) { for (int i = h; i < a.length; i++) { int temp=a[i]; int j; for (j = i; j-h>=0; j-=h) { if(temp<a[j-1]){ a[j]=a[j-h]; }else{ break; } } a[j]=temp; } } } }
The above is the detailed content of Examples of Hill sorting among eight sorting algorithms in Java development. For more information, please follow other related articles on the PHP Chinese website!