import java.util.Arrays; public class Demo { public static void main(String[] args) { int a[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; int[] arr = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; insertSort(arr); } public static void insertSort(int[] a) { int j = 0, i, temp; for (i = 1; i < a.length; i++) { j = i - 1; temp = a[i]; while (j >= 0 && temp < a[j]) { a[j + 1] = a[j]; j--; } a[j + 1] =temp ; System.out.println(Arrays.toString(a)); }} } |