Open DavidVasilev1 opened 8 months ago
This is some test code I did for insertion sorts on my personal notebook:
class Sort { public void insertion(int arr[]) { int n = arr.length; for (int i = 1; i < n; i++) { int x = arr[i]; int j = i - 1; while (j >= 0 && arr[j] > x) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = x; } } static void printArray(int arr[]) { int n = arr.length; for (int i = 0; i < n; ++i) System.out.print(arr[i] + " "); System.out.println(); } // Driver method public static void main(String args[]) { int arr[] = { 12, 11, 13, 5, 6 }; printArray(arr); Sort ob = new Sort(); ob.insertion(arr); printArray(arr); } } Sort.main(null);
This is some test code I did for insertion sorts on my personal notebook: