int a[3] = {12, 15, 17};
int b[4] = { 2, 8, 16, 22};
int c[7] = {0};
int i = 0, j = 0, k = 0;
while (i < 3 && j < 4 ) {
if (a[i] > b[j]) {
c[k++] = b[j++];
} else {
c[k++] = a[i++];
}
}
while (i < 3) {
c[k++] = a[i++];
}
while (j < 4) {
c[k++] = b[j++];
}
for (int i = 0; i < 7; i++) {
printf("%d ", c[i]);
}
将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
时间: 2024-10-03 21:41:29