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

    直接插入排序算法:

    将一个记录插入到已经排好序的有序表中,从而得到一个新的、记录数增1的有序表。

    public class InsertSort {
    
        public static void Sort(int[] L) {
    
            int i;
            int j;
            for (i = 2; i < L.length; i++) {
    
                if (L[i] < L[i - 1]) {
    
                    L[0] = L[i];
                    for (j = i - 1; L[j ] >  L[0]; j --  )
                        L[j + 1] = L[j ];     
                    L[j + 1] =  L[0] ; 
                }
                
            }
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
    
            int[] test = { 0 , 2, 4, 8, 6 , 56, 3, 45, 8, 32 };
    
            Sort(test);
    
            for (int i = 1; i < test.length; i++) {
                System.out.print(test[i] + "  ");
            }
    
        }
    

      

  • 相关阅读:
    Mysql多表关系
    Linux权限
    Linux安装python环境脚本
    ZJNU 2136
    ZJNU 2135
    ZJNU 2133
    ZJNU 1699
    ZJNU 1542
    ZJNU 1538
    ZJNU 1535
  • 原文地址:https://www.cnblogs.com/qgzhan/p/3232569.html
Copyright © 2011-2022 走看看