希尔排序算法代码java【亲测】

  • 希尔排序

public class Sort {

    /**
     * 希尔排序
     */
    void shellSort(int k[],int n){
        int i,j,temp;
        int gap=n;
        do
        {
            gap = gap/3 + 1;
            if(gap=0 && k[j] > temp; j-=gap )
                    {
                        k[j+gap] = k[j];
                    }
                    k[j+gap] = temp;
                }
            }
        }while(gap > 1);
    }
}
  • 测试类

public class Test {
    public static void main(String[] args) {
        int[] arr=new int[]{5, 2, 6, 9, 3, 0, 1, 7, 4, 8};
        Sort s=new Sort();
        s.shellSort(arr,arr.length);
        for(int k=0;k

 

你可能感兴趣的:(数据结构和算法)