-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.cpp
66 lines (64 loc) · 991 Bytes
/
merge.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<iostream>
using namespace std;
int main()
{
int *a=new int[20];
int *b=new int[20];
int *c=new int[30];
int i,j,k,sizeA,sizeB,sizeC;
cout<<"Number of elements in Array 1:"<<endl;
cin>>sizeA;
cout<<"Enter the elements in array:"<<endl;
for(i=0;i<sizeA;i++)
{
cout<<"A["<<i<<"]="<<endl;
cin>>a[i];
}
cout<<"Number of elements in Array 2:"<<endl;
cin>>sizeB;
cout<<"Enter the elements in array:"<<endl;
for(i=0;i<sizeB;i++)
{
cout<<"B["<<i<<"]="<<endl;
cin>>b[i];
}
sizeC=sizeA+sizeB;
i=0;
j=0;
k=0;
while(i<sizeA && j<sizeB)
{
if(a[i]<=b[j])
{
c[k]=a[i];
i++;k++;
}
else
{
c[k]=b[j];
j++; k++;
}
}
cout<<"i"<<i<<"j"<<j;
while(i<sizeA)
{
c[k]=a[i];
k++;
i++;
}
while (j<sizeB)
{
/* code */
c[k]=b[j];
k++;
j++;
}
for(i=0;i<sizeC;i++)
{
cout<<"C["<<i<<"]="<<c[i]<<endl;
}
delete a;
delete b;
delete c;
return 0;
}