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; } } } }
以上是Java开发中八大排序算法之希尔排序实例的详细内容。更多信息请关注PHP中文网其他相关文章!