public class InsertionSort {
public static void main(String[] args) {
int[] array = {5, 2, 8, 12, 1, 6, 4};
System.out.println("Unsorted array: " + Arrays.toString(array));
insertionSort(array);
System.out.println("Sorted array: " + Arrays.toString(array));
}
public static void insertionSort(int[] array) {
int n = array.length;
for (int i = 1; i < n; i++) {
int current = array[i];
int j = i - 1;
while (j >= 0 && array[j] > current) {
array[j + 1] = array[j];
j--;
}
array[j + 1] = current;
}
}
}