Can you check my merge sort implementation? From all of my testing it seems like it works, but I just wanted to make sure I am doing it as good as possible, and it couldn't be optimized any further.
private static void merge(int[] c,int[] a, int[] b){
int i = 0;//index for a
int j = 0;//index for b
for(int k = 0; k < c.length; k++){
//check a[] edge case
if(i >= a.length){
c[k] = b[j];
j++;
}else if(j >= b.length){
c[k] = a[i];
i++;
}else if(a[i] < b[j]) {
c[k] = a[i];
i++;
} else {
c[k] = b[j];
j++;
}
}
}
public static void mergeSort(int[] A){
if(A.length > 1){
int pivot = A.length / 2;
int[] left = Arrays.copyOfRange(A, 0, pivot);
int[] right = Arrays.copyOfRange(A, pivot,A.length);
mergeSort(left);
mergeSort(right);
merge(A,left,right);
}
}