/** * The idea of choosing a sort: * before each loop, the array to the left is a partially ordered sequence, * and then select the right to be sorted elements, to save their values * and then the left side of the elements compared * if less than the left element, the left element to the right one * until and the leftmost
The comparison is complete, or the element to be arranged is not smaller than the left element * * Package Al; public class Insertionsort {public static void main (string[] args) {Insertionsort insertsort = new Ins
Ertionsort ();
Int[] elements = {14, 77, 21, 9, 10, 50, 43, 14};
Sort the array insertsort.sort (elements);
Print the sorted array for (int i = 0; i < elements.length i++) {System.out.print (elements[i));
System.out.print (""); }/** * @author * @param array to row arrays */public void sort (int[] array) {//min to save Minimum element for each round int key; Save current element for (int i=0; i<array.length; i++) {int j = i;
Current position key = Array[j]; Compare current element while (J > 0 && array[j-1] > key) {array[j] = array[j-1];//shift
It j--;
} Array[j] = key;
}
}
}