java data structures - Sorting Algorithm - insertion algorithm

com.kuang Package; 

Import java.util.Arrays;

/ **
* @auther strong Fu
* @date 2020/2/14 - 19:02
* /
public class insertSort {
public static void main (String [] args) {
int [] = ARR new new int [] {} 11,3,2,53,2,5,9,1;
insertSort (ARR);
System.out.println (of Arrays.toString (ARR));
}
public static void insertSort (int [] ARR) {
int = End arr.length;
// iterate through all the numbers
for (int I =. 1; I <End; I ++) {
// if the current than the previous one numeric digit
if (arr [i] <ARR [-I. 1]) {
// save up to the current iteration number
int ARR TEMP = [I];
int J;
// iterate all numbers preceding the current number
for (J =. 1-I; J> = 0 && TEMP <ARR [J]; J -) {
// after the previous number assigned to a digital
arr [j + 1] = arr [J];
}
// after it temporary variables (for the outer loop current element) is assigned an element does not satisfy the condition
ARR [J +. 1] = TEMP;
}
}

}
}

Guess you like

Origin www.cnblogs.com/fuqiang-java/p/12309157.html