-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge.cpp
More file actions
37 lines (35 loc) · 688 Bytes
/
merge.cpp
File metadata and controls
37 lines (35 loc) · 688 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
#include<iostream>
using namespace std;
void Merge(int *arr1,int l, int *arr2,int s)
{
int i,j,k;
i=j=k=0;
int len = 10;
int *arr3 = new int[len];
while(i<l && j<s)
{
if(arr1[i] < arr2[j])
arr3[k++] = arr1[i++];
else if(arr1[i] == arr2[j])
{
arr3[k++] = arr1[i++];
j++;
len--;
}
else
arr3[k++] = arr2[j++];
}
for(;i<l;i++)
arr3[k++] = arr1[i];
for(;j<s;j++)
arr3[k++] = arr2[j];
for(int m=0;m<len;m++)
cout<<arr3[m]<<" ";
}
int main()
{
int ar1[5] = {2,9,21,28,35};
int ar2[5] = {2,3,16,18,28};
Merge(ar1,5,ar2,5);
return 0;
}