zoukankan      html  css  js  c++  java
  • 排序算法总结之希尔排序

    package com.util.sort;
    
    public class ShellSort {
    
    	private long[]theArray;
    	private int nElem;
    	public ShellSort(int max){
    		theArray = new long[max];
    		nElem = 0;
    	}
    	//插入元素
    	public void insert(long value){
    		theArray[nElem] = value;
    		nElem++;
    	}
    	//打印元素
    	public void display(){
    		for (int i = 0;i<theArray.length;i++) {
    			System.out.print(theArray[i]+" ");
    		}
    		System.out.println();
    	}
    	
    	public void sort(){
    		System.out.println("MMMMMMMMMMM");
    		int inner = 0;
    		int outer = 0;
    		long temp = 0;
    		int h = 1;
    		while (h <= nElem/3) 
    			h = h*3+1;
    			while(h > 0){
    				for (outer = h;outer<nElem;outer++) {
    					temp = theArray[outer];
    					inner = outer;
    					while (inner > h-1 && theArray[inner-h] >= temp) {
    						theArray[inner] = theArray[inner-h];
    						inner -= h;
    						
    					}
    					theArray[inner] = temp;
    					
    				}
    				h = (h-1)/3;
    			}
    		
    	}
    	
    	
    }
    
  • 相关阅读:
    php 延迟静态绑定: static关键字
    python分片
    用逗号分隔数字,神奇
    ubuntu 屏幕截图
    js 获取随机数
    netty : NioEventLoopGroup 源码分析
    LinkedList 源码分析
    面向对象
    JS
    网页
  • 原文地址:https://www.cnblogs.com/airycode/p/5193124.html
Copyright © 2011-2022 走看看