直接插入排序

 1 public class IncertSort
 2 {
 3     public static void main(String[] args)
 4     {
 5         int [] array = {49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,56,17,18,23,34,15,35,25,53,51};
 6         int lengthtArray = array.length;
 7         for(int i = 1; i < lengthtArray; i++)
 8         {
 9             int temp = array[i];
10             int j = i - 1;
11             for( ;j >= 0 && temp < array[j]; j--)
12             {
13                 array[j + 1] = array[j];
14             }
15             array[j + 1] = temp;
16         }
17        for(int i=0;i<lengthtArray;i++)
18         {  
19              System.out.print(" " + array[i]);  
20         }  
21     }
22 }
View Code

1.直接插入排序

(1)基本思想:在要排序的一组数中,假设前面(n-1)[n>=2] 个数已经是排

好顺序的,现在要把第n个数插到前面的有序数中,使得这n个数

也是排好顺序的。如此反复循环,直到全部排好顺序。

原文地址:https://www.cnblogs.com/Kermit-Li/p/4152214.html