Eight kinds of ordering relationships:

Insert sort directly

Basic idea:

In the set of numbers to be sorted, assume that the preceding (n-1)[n>=2] number is already row

Okay, so now we’re going to insert the NTH number into the ordered number, so that this n number

It’s also in order. Repeat until everything is sorted.



In the following

Code implementation:

public class InsertSort { public static void main(String[] args) { int 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 a [] = {}; for (int i = 0; i < a.length-1; Int j = I; int j = I; int j = I; int j = I; int insertNum = a[j+1]; While (j >= 0 &&a [j] > insertNum) {a[j+1] = a[j]; j--; } // Because of the previous loop, exit j minus one again, if ((j+1)! = i) { a[j+1] = insertNum; } } for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); }}}Copy the code