Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
merge without extra space Gap method ALgorithm
#include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; vector<int>v1(n); vector<int>v2(m); for(int i=0;i<n;i++) cin>>v1[i]; for(int j=0;j<m;j++) cin>>v2[j]; cout<<"INPUT"<<endl; for(int i=0;i<n;i++) cout<<v1[i]<<" "; cout<<endl; for(int j=0;j<m;j++) cout<<v2[j]<<" "; cout<<endl; int gap=(m+n)/2+(m+n)%2; while(gap>0) { int i,j; for(i=0;i+gap<n;i++) { if(v1[i]>v1[i+gap]) { swap(v1[i],v1[i+gap]); } } for(j=gap>n?gap-n:0;i<n && j<m;j++,i++) { if(v1[i]>v2[j]) swap(v1[i],v2[j]); } if(j<m) { for(j=0;j+gap<m;j++) { if(v2[j]>v2[j+gap]) swap(v2[j],v2[j+gap]); } } if(gap==1) { gap=gap/2; } else { gap=gap/2+gap%2; } } cout<<"output"<<endl; for(int i=0;i<n;i++) cout<<v1[i]<<" "; cout<<endl; for(int i=0;i<m;i++) cout<<v2[i]<<" "; cout<<endl; }
run
|
edit
|
history
|
help
0
How to get base class
DP on Trees: Type B (In/out Dp)
test
BInTree Traversal
friend function
Matrix spiral print
ThreadPool
DeltaX campus recruitment
project: bank account
mergeSort