#include #include #define PRVKU1 8 #define PRVKU2 6 int pole1[] = {2, 4, 7, 8, 8, 8, 10, 11}; int pole2[] = {1, 6, 8, 9, 18, 20}; int pole3[PRVKU1 + PRVKU2]; /* Předpokládejme, že PRVKU1 > 0, PRVKU2 > 0 */ int merge() { int i, j, k; k = 0; j = 0; for (i = 0; i < PRVKU1; i++) { while (pole2[j] <= pole1[i]) { pole3[k] = pole2[j]; j++; k++; if (j == PRVKU2) { while (i < PRVKU1) { pole3[k] = pole1[i]; i++; k++; } return; } } pole3[k] = pole1[i]; k++; } while (j < PRVKU2) { pole3[k] = pole2[j]; j++; k++; } } int main() { int i; merge(); for (i = 0; i < PRVKU1 + PRVKU2; i++) printf("%d, ", pole3[i]); printf("\n"); }