1, algorithm concept.
Each time the first element is removed from the unordered table, it is inserted into the proper position of the ordered table, so that the ordered table is still orderly.
2, algorithmic thinking.
Suppose the records to be sorted are stored in array R[1..N]. Initially, the r[1] is a 1 ordered region and the disordered region is R[2..N]. From i=2 up to I=n, the r[i] is inserted into the current ordered region r[1..i-1, in order to generate an ordered region containing N records.
public static void Insertsort (int[] array) {
int len = array.length;
for (int i = 1; i < Len; i++) {for
(int j = i; j > 0; j--) {
if (Array[j] < array[j-1]) {
Sort.swa P (Array, J, j-1);//Swap J and J-1
} else break
;}
}
Insert Sort diagram:
The above is to share all the content of this article, I hope to be able to understand the insertion of a sorting algorithm to help.