-
Notifications
You must be signed in to change notification settings - Fork 0
/
2pointer5.cpp
53 lines (50 loc) · 1.05 KB
/
2pointer5.cpp
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
47
48
49
50
51
52
53
// //-------------------------------------------------------------------
// //======================= Eslam_Eed01 =================================
#include <bits/stdc++.h>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> v32;
typedef vector<ll> v64;
#define ln "\n"
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define eslam_fast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//merge sorted array using two pointer
int main()
{
eslam_fast();
vector<int>v;
int n;cin>>n;
int p1=0,p2=0;
int arr1[100];
int arr2[100];
forn(i,n)cin>>arr1[i];
forn(i,n)cin>>arr2[i];
while(p1<n||p2<n)
{
if(arr1[p1]<=arr2[p2]&&p1<n)
{
v.push_back(arr1[p1]);
p1++;
}
else if(arr1[p1]>=arr2[p2]&&p2<n)
{
v.push_back(arr2[p2]);
p2++;
}
else if (p1<n)
{
v.push_back(arr1[p1]);
p1++;
}
else if (p2<n)
{
v.push_back(arr2[p2]);
p2++;
}
}
for (auto i:v)cout<<i<<" ";
}