#include
#include
#define SIZE 20
class array
{
int a[SIZE];
int n;
public:
array();
void read();
void sort(array,array);
void merge(array,array);
void display();
};
array::array()
{
int i;
n=0;
for(i=0;i
if(n>SIZE)
{
cout<<"The array cannot hold "<
}
}
void array::sort(array a1,array a2)
{
int i,j,ch,temp;
for(i=0;i
{
temp=a1.a[i];
a1.a[i]=a1.a[j];
a1.a[j]=temp;
}
}
}
for(i=0;i
{
cout<<"\nCannot perform merging...array cannot hold elements!!!";
}
else
{
for(i=0,j=0;i<(arr1.n+arr2.n);i++,j++)
{
a[i]=arr2.a[j];
}
}
}
void array::display()
{
int i;
for(i=0;i
{
cout<<" "<
}
}
void main()
{
array a1,a2,a3;
a1.read();
a2.read();
cout<<"\nThe first array is \n";
a1.display();
cout<<"\nThe Second array is \n";
a2.display();
a3.merge(a1,a2);
cout<<"\nThe merged array is\n";
a3.display();
getch();
}
No comments:
Post a Comment