Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void Insertion(int a[],int n,int b[],int m)
- {
- int * A=new int [n];
- int k=1;
- for (int PosA=0,PosB=0;PosA<n && PosB<m;)
- {
- if (PosA<n && a[PosA]<b[PosB]) PosA++;
- else if (PosB<m && a[PosA]>b[PosB]) PosB++;
- else if (PosB<m && PosA<n && a[PosA]==b[PosB]) {A[k]=a[PosA];PosA++; PosB++;k++;}
- }
- for (int j=1;j<k;j++)
- {
- if ( A[j]!=A[j-1]) cout<<A[j]<<" ";
- }
- }
- int main()
- {
- int n,m;
- cin>>n;
- int * A=new int [n];
- for (int i=0;i<n;i++)
- {
- cin>>A[i];
- }
- cin>>m;
- int * B=new int [m];
- for (int i=0;i<m;i++)
- {
- cin>>B[i];
- }
- Insertion(A,n,B,m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement