i’ve been trying to use for loop for sorting algorithm but there are errors - index out of bound error
code :
public static void insertion_Sorting(int[] arr){
// count:No of arrays sorted
for(int i=1;i<arr.length;i++){
int val=arr[i];
int jj = i - 1;
for (int j=i-1;arr[j]>arr[i] && j>=0;j–){
jj=j;
arr[j+1]=arr[j];
}
arr[jj]=val;
}
}
it is function made by me
pls guide me how to do insertion sorting using for loop and where i’m wrong