Advertisement
SergeyPGUTI

6.3.4

Nov 21st, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void merge  (int  A[],  int  n,  int  B[],  int m,  int  C[])
  6.  
  7. {
  8.     for (int i=0,Apos=0,Bpos=0;i<n+m;i++)
  9.     {
  10.         if ( Apos<(n) && A[Apos] <= B[Bpos]) {C[i]=A[Apos]; Apos++; }
  11.             else if (Bpos<m) {C[i]=B[Bpos];Bpos++;};
  12.     }
  13.  
  14. }
  15.  
  16. int main()
  17. {
  18.     int n,m;
  19.     int * A, * B,* C;
  20.     cin>>n;
  21.     A=new int [n];
  22.     for (int i=0;i<n;i++)
  23.     {
  24.         cin>>A[i];
  25.     }
  26.     cin>>m;
  27.     B=new int [m];
  28.     for (int i=0;i<m;i++)
  29.     {
  30.         cin>>B[i];
  31.     }
  32.     C=new int [n+m];
  33.     merge(A,n,B,m,C);
  34.     for (int i=0;i<m+n;i++)
  35.     {
  36.         cout<<C[i]<<" ";
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement