zoukankan      html  css  js  c++  java
  • ShellSort

    public class ShellSort {
    public static void main(String[] args) {
        int A[] = { 5, 2, 9, 4, 7, 6, 1, 3, 8 };// 从小到大希尔排序
        sort(A,A.length);
        for (int i = 0; i < A.length; i++)
        {
            System.out.printf("%d ", A[i]);
        }
    }
    public static void sort(int A[], int n){
        int h = 0;
        while (h <= n)                          // 生成初始增量
        {
            h = 3 * h + 1;
        }
        while (h >= 1)
        {
            for (int i = h; i < n; i++)
            {
                int j = i - h;
                int get = A[i];
                while (j >= 0 && A[j] > get)
                {
                    A[j + h] = A[j];
                    j = j - h;
                }
                A[j + h] = get;
            }
            h = (h - 1) / 3;                    // 递减增量
        }
    }
    }
  • 相关阅读:
    052-34
    052-33
    052-32
    052-31
    052-30
    052-28
    react组件之间通信
    排序算法
    点外卖
    js的各种排序算法
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/8046261.html
Copyright © 2011-2022 走看看