/*
* Two Order Array merge One Order Array
*/
public class SortOrder{
public static void main(String [] args){
int array1[]={5,34,2,57,78},array2[]={67,43,26,47,87,85};
int s1=array1.length, i1=0;
int s2=array2.length, i2=0;
int total=s1+s2, index=0;
int dest[] = new int[total];
while(i1<s1 && i2<s2)
{
if(array1[i1]<array2[i2])
dest[index++]=array1[i1++];
else
dest[index++]=array2[i2++];
}
//if array1 left element
while(i1<s1)
dest[index++]=array1[i1++];
//if array2 left element
while(i2<s2)
dest[index++]=array2[i2++];
for(int i=0; i < total;i++)
System.out.println("dest["+i+"]="+dest[i]);
}
}
Order Array
最新推荐文章于 2020-04-04 16:28:22 发布