# c++编程：

0

jewfer | 初学一级 | 园豆：192

0

template <typename T>
void mymerge(const T a, int a_len, const T b, int b_len, T* c)
{
int i, j, k;
i = j = k = 0;
if(a_len == 0) {
goto line1;
} else if(b_len == 0) {
goto line2;
}
while(true) {
if(a[i] < b[j]) {
c[k++] = a[i++];
if(i==a_len) {
line1:
while(j<b_len) {
c[k++] = b[j++];
}
return;
}
} else {
c[k++] = b[j++];
if(j==b_len) {
line2:
while(i<a_len) {
c[k++] = a[i++];
}
return;
}
}
}
}

0
``````    int a[1000005];
int* findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
int i=0,j=0,int tag=0;
while(i<nums1.size()&&j<nums2.size())
{
if(nums1[i]<=nums2[j])
a[tag++]=nums1[i++];
else
a[tag++]=nums2[j++];
}
while(i<nums1.size())   {  a[tag++]=nums1[i++];  }
while(j<nums2.size())  {  a[tag++]=nums2[j++];  }
return a;
}``````
Shendu.CC | 园豆：2138 (老鸟四级) | 2018-11-26 11:22

@古宇: 大佬过赞了！

0

int* sortAndCombine2Array(int array1[] , int array1Len, int array2[] , int array2Len)
{
int i = array1Len;
int j = array2Len;
int k = 0;
int *retArray = NULL;
int array3Len = array1Len + array2Len;

``````if(array3Len){
retArray =(int*)malloc(array3Len * sizeof(int));
//
//c plus plus use new!
//
while(i && j){
(array1[array1Len - i] > array2[array2Len - j] ) ? (retArray[k++] = array2[array2Len - j--]) : (retArray[k++] = array1[array1Len - i--]);
}

while(i){
retArray[k++] = array1[array1Len - i--];
}
while(j){
retArray[k++] = array2[array2Len - j--];
}
}
return retArray;``````

}

liqinghan | 园豆：219 (菜鸟二级) | 2018-12-04 17:06

您需要登录以后才能回答，未注册用户请先注册