67,513
社区成员
发帖
与我相关
我的任务
分享
public class Test3 {
public static void main(String args[]) {
int a[] = {1,4,31,41,51};
int b[] = {11,22,32,42,52,54};
int c[] = sort(a,b);
for(int n=0; n<c.length; n++)
System.out.println(c[n]);
}
public static int[] sort(int[] a,int[] b){
int[] c=new int[a.length+b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
for(int i=0;i<c.length;i++){
for(int j=0;j<c.length-i-1;j++){
int x=c[i];
int y=c[i+1];
if(x>y){
c[i+1]=x;
c[i]=y;
}
}
}
return c;
}
}
public class test {
public static void main(String args[]) {
int a[] = {1,4,31,41,51};
int b[] = {11,22,32,42,52,54};
int c[] = sort(a,b);
for(int n=0; n<c.length; n++)
System.out.println(c[n]);
}
private static int[] sort(int[] a, int[] b) {
int c[] = new int[a.length+b.length];
int n = 0;
int i = 0;
int j = 0;
while(i<a.length&&j<b.length) {
if(a[i]<b[j]) {
c[n] = a[i];
n++;
i++;
}else {
c[n] = b[j];
n++;
j++;
}
}
while(i<a.length) {
c[n] = a[i];
n++;
i++;
}
while(j<b.length) {
c[n] = b[j];
n++;
j++;
}
return c;
}
}