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; } } } }
Atas ialah kandungan terperinci Java开发中八大排序算法之希尔排序实例. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!