zoukankan      html  css  js  c++  java
  • 希尔排序

    package com.insert;
    
    import java.util.Arrays;
    
    /**
     * 希尔排序
     * 
     * @author wanjn
     *
     */
    public class ShellSort {
        public static void main(String[] args) {
            int[] a = { 50, 3, 6, 1, 7, 9, 6, 2, 23, 5, 7, 234, 34, 6, 2, 7, 99,
                    65, 3, 5, 675, 23 };
            int[] b = { 9, 5, 1 };
            System.out.println(Arrays.toString(shellInsertSort(a, b)));
            ;
        }
    
        private static int[] shellInsertSort(int[] a, int[] b) {
            int temp;
            int j;
            int addIndex;
            //可以和直接插入排序代码类比,基本上相同,只是比较一次移动的范围是一个增量序列
            for (int k = 0; k < b.length; k++) {
                //增量序列
                addIndex = b[k];
                for (int i = addIndex; i < a.length; i++) {
                    temp = a[i];
                    for (j = i - addIndex; j >= 0 && temp < a[j]; j-=addIndex) {
                        a[j + addIndex] = a[j];
                    }
                    a[j + addIndex] = temp;
                }
            }
            return a;
        }
    }
  • 相关阅读:
    python中的keys、values、items
    python中的del
    python中的reverse
    python中的remove
    python中的pop
    zookeeper for windows
    express
    js undefine,null 和NaN
    Think_php入口文件配置
    jquery 集合操作
  • 原文地址:https://www.cnblogs.com/wanjn/p/8575856.html
Copyright © 2011-2022 走看看