#include <stdio.h>
void show(int* p, int len)
{
for (int i = 0; i < len; ++i)
{
printf("%d,", p[i]);
}
puts("\b");
}
void arrayMerge(int* p1, int len1, int* p2, int len2, int* p3)
{
int i ,j ,k ;
i = j = k = 0;
while (i < len1&&j < len2)
{
if (p1[i] > p2[j])
p3[k++] = p2[j++];
else
p3[k++] = p1[i++];
}
while (i < len1)
{
p3[k++] = p1[i++];
}
while (j < len2)
{
p3[k++] = p2[j++];
}
}
void main()
{
int a[] = { 2,3,5,8,12,26 ,30};
int b[] = { 1,4,5,7,9,13 };
int c[100];
int len1 = sizeof(a) / sizeof(a[0]);
int len2 = sizeof(b) / sizeof(b[0]);
int len3 = len1 + len2;
arrayMerge(a, len1, b, len2, c);
show(c, len3);
}
把两个已按升序排列的数组合并成一个升序数组,要求用函数实现
最新推荐文章于 2024-04-17 16:05:07 发布