// "static void main" must be defined in a public class.
public class Main {
public static void main(String[] args) {
int[] a = {7,1,4,9,7,6,5,3};
SortArray(a);
System.out.println("Hello World!");
}
public static int[] SortTwoArray(int[] a, int[] b){
int i = 0;
int j = 0;
int zmax = a.length + b.length;
int[] c = new int[zmax];
for(int z = 0 ; z < zmax; z++){
if (i == a.length){
c[z] = b[j];
j++;
}else if(j == b.length){
c[z] = a[i];
i++;
}else{
if(a[i] >= b[j]){
c[z] = b[j];
j++;
}else{
c[z] = a[i];
i++;
}
}
}
System.out.println("a = {" + Arrays.toString(a) + "}, b = {" + Arrays.toString(b) + "}, c = {" + Arrays.toString(c) + "}");
return c;
}
public static int[] SortArray(int[] a){
if (a.length > 1){
int index = a.length / 2;
int[] x = new int[index];
int[] y = new int[a.length - index];
for(int q = 0; q < index; q++){
x[q] = a[q];
}
for(int p = index; p < a.length; p++){
y[p - index] = a[p];
}
System.out.println("x = {" + Arrays.toString(x) + "}, y = {" + Arrays.toString(y) + "}");
return SortTwoArray(SortArray(x),SortArray(y));
}else{
return a;
}
}
}
11-04