import java.lang.reflect.Array;
import java.util.Arrays;
public class SortMain {
public static void main(String[] args) {
// 定义升序数组
int[] a = { 1, 4, 6, 7, 8 };
int[] b = { 2,3,4, 5, 6, 9, 10 };
int[] c = { 20,40,100 };
int[] d = { 30,50,100 };
final int[] ints = sortAll(a, b, c, d);
System.out.println(Arrays.toString(ints));
}
private static int[] sortAll(int[] a, int[] b, int[] c, int[] d) {
int[] sort = sort(a, b);
sort(sort,c);
return sort(sort,d);
}
private static int[] sort(int[] a, int[] b) {
int[] c=new int[a.length+b.length];
int left=0;
int right=0;
for (int i = 0; i < c.length; i++) {
if(left<a.length && b.length>right){
if(a[left] > b[right]){
c[i]=b[right];
right++;
}
else{
c[i]=a[left];
left++;
}
}
else if(left <a.length){
c[i]=a[left];
left++;
}
else if(right<b.length){
c[i]=b[right];
right++;
}
}
return c;
}
}
|