I have been learning insertion sort currently, and came up with this code:
public int[] Sort(int a[]){
for(int i=1;i<a.length;i++){
int term=a[i];
int j=i-1;
//Sorting
while(j>=0 && term<a[j]){
a[j+1]=a[j];
j--;
}
a[j]=term;
}
return a;
}
But when i execute this code, it shows ArrayIndexOutofBoundsException.
Please guide me wherever i am wrong.