-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday30.cpp
More file actions
46 lines (41 loc) · 959 Bytes
/
day30.cpp
File metadata and controls
46 lines (41 loc) · 959 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
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
// Inplace merge two sorted arrays
void printArray(vector<int>&arr, vector<int>&brr,int n,int m){
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
cout<<endl;
for(int i=0;i<m;i++)
cout<<brr[i]<<" ";
cout<<endl;
return;
}
void sortArrays(vector<int>&arr, vector<int>&brr,int n,int m){
// X[] = 1 4 7 8 10
// Y[] = 2 3 9
int p=0;
for(int i=0;i<n;i++){
if(arr[i]>brr[0]){
swap(arr[i],brr[0]);
int sm = brr[0];
// Now fix brr[0] which is = sm
int j=0;
for(j=1;j<m&&brr[j]<sm;j++){
brr[j-1]=brr[j];
}
brr[j-1]=sm;
}
}
}
main(){
int n,m,i,j,k;
cin>>n>>m;
vector<int>arr(n);
vector<int>brr(m);
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<m;i++)
cin>>brr[i];
sortArrays(arr,brr,n,m);
printArray(arr,brr,n,m);
}