zoukankan      html  css  js  c++  java
  • 插入排序

    概述

    递增方式插入排序

    代码

    package com.lilei.myes.es.pack1114;
    
    import java.util.Random;
    
    public class insert_sort {
    
    	public static void main(String[] args) {
    
    		Random rand = new Random();
    		
    		int[] array = new int[10];
    		
    		for(int i=0;i<array.length;i++)
    			array[i] = rand.nextInt(100);
    		
    		for(int v:array)
    			System.out.print(v+",");
    		
    		System.out.println();
    		
    		sort(array);
    		
    		for(int v:array)
    			System.out.print(v+",");
    		
    	}
    
    	static void sort(int[] array) {
    
    		for (int i = 1; i < array.length; i++) {
    
    			int p = i - 1;
    			int value = array[i];
    
    			while (p >= 0 && value < array[p])
    			{
    				array[p+1] = array[p];
    				p--;
    			}
    			
    			if (p != i-1)
    				array[p+1] = value;
    
    		}
    
    	}
    
    }
    

      

  • 相关阅读:
    python
    python
    python
    python
    python 序列化
    字典
    异常处理
    类的成员,类的特殊方法
    HTMLEditor类常用方法说明
    HTMLEditor类常用属性说明
  • 原文地址:https://www.cnblogs.com/lilei2blog/p/7832649.html
Copyright © 2011-2022 走看看