• 希尔排序


    package cn.aust.zyw.demo;
    
    /**
     * Created by zyw on 2016/2/9.
     */
    public class Shell {
        public static void sort(int a[]){
            int N=a.length;
            int h=1;
            while(h<N/4) h=4*h+1;//divide in four
            while (h>=1){
                for(int i=h;i<N;i++){
                    for(int j=i;j>=h&&less(a[j],a[j-h]);j-=h)
                        exch(a,j,j-h);
                }
                h=h/4;
            }
        }
        private static boolean less(int  v, int w){
            if(v<w) return true;
            return false;
        }
        private static void exch(int[] a,int i,int j){
            int t=a[i];a[i]=a[j];a[j]=t;
        }
        private static void show(int[] a){
            for(int i=0;i<a.length;i++){
                System.out.printf(a[i]+" ");
            }
        }
        public static boolean isSorted(int[] a){
            for(int i=1;i<a.length;i++)
                if(less(a[i],a[i-1])) return false;
            return true;
        }
        public static  void main(String args[]){
            int a[]={20,5,14,3,63,1,55,11,0};
            sort(a);
            show(a);
        }
    }
  • 相关阅读:
    2021年2月4号
    2021年2月3号
    2021年2月2号
    2021年2月1日
    2021年1月31日
    2021年1月30日
    20171205xlVBA往返航班组合
    选择文件
    从VBA过渡到Python
    20171114xlVba选定单行记录并打印
  • 原文地址:https://www.cnblogs.com/yunwuzhan/p/5191417.html
Copyright © 2020-2023  润新知