public class MergeSortArray {
public static int[] sort(int[] a,int[] b){//a,b数组必须有序
int merge[]=new int[a.length+b.length];
int lenA=0,lenB=0,lenMer=0;
while(lenA<a.length&&lenb<b.length){
if(a[lenA]<b[lenb]){
merge[lenMer++]=a[lenA++];
}else{
merge[lenMer++]=b[lenB++];
}
}
while(lenA<a.length){
merge[lenMer++]=a[lenA++];
}
while(lenB<b.length){
merge[lenMer++]=b[lenB++];
}
return merge;
}
public static void main(String[] args) {
int[] a={1,2,3,3,4,5};
int[] b={7,8,8,9};
int[] c=MergeSortArray.sort(a, b);
for (int i : c) {
System.out.print(i);
System.out.print(" ");
}
}
}
网友评论