经典指数          
原因
1603
浏览数
0
收藏数
 

Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.

     举报   纠错  
 
切换
1 个答案
//思路是:有序数组的归并排序。 void merge(intA[], intm, intB[], intn) {         int temp[m+n]={0};         inti =0;         intj = 0;         intindex = 0;         while(i < m && j < n){             if(A[i] >= B[j]){                 temp[index++] = B[j++];             }else{                 temp[index++] = A[i++];             }        }         while(i < m){             temp[index++] = A[i++];         }         while(j < n){             temp[index++] = B[j++];        }         for(i = 0; i < index; i++){             A[i] = temp[i];        }    } }
 
切换
撰写答案
扫描后移动端查看本题