-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergewithoutspace.cpp
More file actions
38 lines (33 loc) · 864 Bytes
/
Copy pathmergewithoutspace.cpp
File metadata and controls
38 lines (33 loc) · 864 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
#include<bits/stdc++.h>
using namespace std;
int merge(int arr1[],int arr2[],int m,int n){
for(int i=0;i<m;i++){
if(arr1[i]>arr2[0]){
int temp=arr1[i];
arr1[i]=arr2[0];
arr2[0]=temp;
}
int j=0;
while((j+1<n) && (arr2[j]>arr2[j+1])){
int temp=arr2[j];
arr2[j]=arr2[j+1];
arr2[j+1]=temp;
j++;
}
}
}
int main(){
int arr1[]={1,2,6,8};
int m=sizeof(arr1)/sizeof(arr1[0]);
int arr2[]={3,5,7};
int n=sizeof(arr2)/sizeof(arr2[0]);
merge(arr1,arr2,m,n);
cout<<"\nfirst array after merging ";
for(int i=0;i<m;i++){
cout<<arr1[i]<<" ";
}
cout<<"\nsecond array after merging ";
for(int j=0;j<n;j++){
cout<<arr2[j]<<" ";
}
}