Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void merge (int A[], int n, int B[], int m, int C[])
- {
- for (int i=0,Apos=0,Bpos=0;i<n+m;i++)
- {
- if ( Apos<(n) && A[Apos] <= B[Bpos]) {C[i]=A[Apos]; Apos++; }
- else if (Bpos<m) {C[i]=B[Bpos];Bpos++;};
- }
- }
- int main()
- {
- int n,m;
- int * A, * B,* C;
- cin>>n;
- A=new int [n];
- for (int i=0;i<n;i++)
- {
- cin>>A[i];
- }
- cin>>m;
- B=new int [m];
- for (int i=0;i<m;i++)
- {
- cin>>B[i];
- }
- C=new int [n+m];
- merge(A,n,B,m,C);
- for (int i=0;i<m+n;i++)
- {
- cout<<C[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement