-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB Q-10.cpp
More file actions
42 lines (41 loc) · 773 Bytes
/
Copy pathLAB Q-10.cpp
File metadata and controls
42 lines (41 loc) · 773 Bytes
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
#include<iostream>
using namespace std;
int merge(int *A, int M, int *B, int N, int *C)
{ //Enter your code here
int p = 0;
int q = 0;
int k = 0;
int c=0;
while ( p < M && q < N) {
if (A[p] < B[q])
{
C[k++] = A[p++];
c++;
}
else {
C[k++] = B[q++];
c++; }
}
while ( p < M) {
C[k++] = A[p++];
}
while ( q < N) {
C[k++] = B[q++];
}
return c;
}
int main()
{
int i,M,N;
cin >> M >> N;
int A[M],B[N],C[M+N];
int X;
for(i=0;i<=M-1;i++)
cin >> A[i];
for(i=0;i<=N-1;i++)
cin >> B[i];
X = merge(A,M,B,N,C);
for(i=0;i<=M+N-1;i++)
cout << C[i] << " ";
cout << endl << X;
return 0; }