/*Merging two arrays in third array in sorted order using merge sort,duplicate values in both the arrays are sorted once only in
//not working /*Merging two arrays in third array in sorted order using merge sort,duplicate values in both the arrays are sorted once only in third array*/ #include<iostream.h> #define MAX 100 class Asending { int arr[MAX]; public: int size; Ascending() { size=0; } Ascending(int n) { size=n; } void input(); void sort(); void displayList(); Ascending merge(Ascending d); }; void Ascending::input() { for(int i=0;i<size;i++) { cout<<"enter a no"; cin>>arr[i]; } sort(); displayList(); } void Ascending::sort() { int i,j,temp; for(i=0;i<size-1;i++) { for(j=i+1;j<size;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } void Ascending::displayList() { cout<<"Array element:"; for(int i=0;i<size;i++) { cout<<arr[i]<<" "; } cout<<endl; } Ascending Ascending::merge(Ascending d) { Ascending temp; temp.size=size+d.size; int i,j,k,t; for(i=j=k=0; ;k++) { if(arr[i]<d. arrLiJ) { temp.arr[k]=arr[i++]; } else if(arr[i]==d.arr[j]) { temp.arr[k]=arr[i++]; j++; temp.size--; } else { temp.arr[k]=d.arr[j++]; } if(i==size||j===d.size) { break; } } for(k++;i<size;i++) { temp.arr[k++]=arr[i]; } for( ;j<d.size;j++) { temp.arr[k++]=d.arr[j]; } for(i=0;i<temp. size;i++) { return temp; } } void main() { Ascending al(5),a2(5),a3( 10); al.input(); a2.input(); a3==a1.merge(a2); a3.displayList(); getch(); } //showing errors