Array method (provided that the two sequential tables are sorted, and if they are not sorted, they are sorted and then merged)
#include <iostream>using namespace std;//create order table void Create (int a[],int length) {for (int i=0;i<length;i++) { cin>>a[i]; }} Print order table void Show (int a[],int length) { cout<<a[0]; for (int i=1;i<length;i++) { cout<< ' <<A[i]; } Cout<<endl;} Merge Order table int mergelist (int a[],int la,int b[],int lb,int c[]) { int i=0,j=0,k=0; while (I<la && j<lb) { if (A[i]<b[j]) { c[k++]=a[i++]; } else { c[k++]=b[j++]; } } while (I<la) { c[k++]=a[i++]; } while (j<lb) { c[k++]=b[j++]; } return k;} int main () { int a[20],b[20],c[40]; int la,lb; Enter the length of a, B, while (cin>>la>>lb) {Create (A,LA);//create Order table A create (B,LB);//create Order table B int Temp=mergelist (a,la,b,lb,c); Show (c,temp);} }
Two linear table merges