#include <stdio.h>
int main() {
int ai = 0, bi = 0, ci = 0, m;
int a[] = {7,8,9,10,11,12}; //定义两个数组
int b[] = {3, 4, 5, 6, 7};
int c[11] = {0};
int alen = 6, blen = 5;
while (ai < alen && bi < blen) {
if (a[ai] < b[bi])
c[ci++] = a[ai++];
else if (a[ai] > b[bi])
c[ci++] = b[bi++];
else
c[ci++] = a[ai++], bi++;
/* c[ci++]= a[ai++];
c[ci++]=b[bi++];*/ //集合数字需要重复时
}
while (ai < alen)
c[ci++] = a[ai++];
while (bi < blen)
c[ci++] = b[bi++];
for (m = 0; m < ci; m++)
printf("%d ", c[m]);
return 0;
}
两个集合(数组)的合并
最新推荐文章于 2024-11-05 13:15:38 发布