C语言指针实现两个有序数组的合并排序
#include <stdio.h>
void printIncreasingOrder(int *a, int *b, int size) {
int i = 0, j = 0, k = 0;
int c[20];
while (i < size && j < size) {
if (a[i] < b[j]) {
c[k++] = a[i++];
} else {
c[k++] = b[j++];
}
}
while (i < size) {
c[k++] = a[i++];
}
while (j < size) {
c[k++] = b[j++];
}
printf('The elements in increasing order: ');
for (int m = 0; m < 2 * size; m++) {
printf('%d ', c[m]);
}
printf('
');
}
int main() {
int a[10] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
int b[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
printIncreasingOrder(a, b, 10);
return 0;
}
原文地址: http://www.cveoy.top/t/topic/n0lz 著作权归作者所有。请勿转载和采集!