1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include <stdio.h>
int *Merge(int *a, int n, int *b, int m) { int *res = (int*)malloc(sizeof(int)*(n+m)), *p = res, *q = a; for(int i = 0; i < n+m; i++) { if(i == n) q = b; *(p++) = *(q++); } return res; }
void sortting(int *arr, int n) { int temp; for(int i = 0; i < n-1; i++) { for(int j = 0; j < n-1; j++) { if(*(arr+j) > *(arr+j+1)) { temp = *(arr+j); *(arr+j) = *(arr+j+1); *(arr+j+1) = temp; } } } }
void display(int *res, int n, int m) { for(int i = 0; i < m+n; i++) { if(i == 0) printf("%d", *(res+i)); else printf(" %d", *(res+i)); } }
void input(int *arr, int n) { for(int i = 0; i < n; i++) { scanf("%d", arr+i); } }
void create(int **a, int *n, int **b, int *m) { scanf("%d %d", n, m); *a = (int*)malloc(sizeof(int)*(*n)), *b = (int*)malloc(sizeof(int)*(*m)); }
int main() { int *a, *b, n, m; create(&a, &n, &b, &m); input(a, n); input(b, m); sortting(a, n); sortting(b, m); int *res = Merge(a, n, b, m); display(res, n, m); }
|