#include
using namespace std;
class median_merge_array{
public:
int *p;
int size1;
public:
median_merge_array(int s){
p=new int[s];
size1=s;
}
median_merge_array(int s1,int s2){
int s=s1+s2;
p=new int[s];
size1=s1+s2;
}
void get_input_array(){
for(int i=0;i<size1;i++)
cin>>p[i];
}
median_merge_array merge(median_merge_array a2){
int index1=0,index2=0,index=0;
median_merge_array a(size1,size1);
while(index1<size1 && index2<a2.size1){
while(p[index1]<=a2.p[index2]){
a.p[index]=p[index1];
index++;
index1++;
}
while(p[index1]>=a2.p[index2]){
a.p[index]=a2.p[index2];
index++;
index2++;
}
}
while(index1!=size1){
a.p[index]=p[index1];
index++;
index1++;
cout<<index<<" ";
}
while(index2!=a2.size1){
a.p[index]=a2.p[index2];
index++;
index2++;
cout<<index<<" ";
}
return a;
}
int median(){
if(size1&1==1){
int mid=size1/2;
return p[mid];
}
else{
int mid1=size1/2;
int mid2=mid1+1;
int med=(p[mid1]+p[mid2])/2;
return p[med];
}
}
};
int main(){
int size1;
cin>>size1;
median_merge_array a1(size1);
median_merge_array a2(size1);
median_merge_array a(size1,size1);
a1.get_input_array();
a2.get_input_array();
a=a1.merge(a2);
int med=a.median();
cout<<med<<endl;
return 0;
}
i am try it oop concept but it give run time error