int [] queue1 = {4,7,2,9,12,35,8,49};
int [] queue2 = {24,53,6,19,41,71,1,68,11,32,99}
int[]mergeQ = new int[queue1.length + queue2.length];
for(int i=0; i < queue1.length; i++)
{
mergeQ[i*2] = queue1[i];
mergeQ[i*2+1] = queue2[i];
}
for(int i=0; i < mergeQ.length; i++) {
System.out.print(mergeQ[i]+",");
}
輸出:4,24,7,53,2,6,9,19,12,41,35,71,8,1,49,68,0,0,0將兩個數組合併爲一個
我怎樣才能打印出隊列2的其他元素?
你沒有把在所有數字在'queue2',所以'mergeQ的端部'是0. – nhahtdh