hi everyone im studing computer science , i have question about margeSorting i do not undrstant how it going ???
i do not know where i shold put my question
public static int[] mergeSort(int[] a) {
if (a.length == 1) {
return a;
} else {
int n = a.length / 2;
int b[] = new int[n];
int c[] = new int[a.length - n];
int i;
for (i = 0; i < a.length; i++) {
if (i < n) {
b[i] = a[i];
} else {
c[i - n] = a[i];
}
}
b = mergeSort(b);
c = mergeSort(c);
a = merge(b, c);
return a;
}
}
public static int[] merge(int[] A, int[] B) {
int c[] = new int[A.length + B.length];
int i, a = 0, b = 0;
for (i = 0; i < A.length + B.length; i++) {
if (a == A.length) {
c[i] = B[b];
++b;
} else if (b == B.length) {
c[i] = A[a];
++a;
} else if (A[a] > B[b]) {
c[i] = B[b];
++b;
} else {
c[i] = A[a];
++a;
}
}
return c;
}