The essence is the merging of two arrays (the order table is best ordered)
#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;} void _insert (int a[],int &length,int n) {int i=0; while (i<length&&a[i]<n) {i++; } int temp=i; I=length; while (i>temp) {a[i]=a[i-1]; i--; } a[temp]=n; length++;} int locate (int a[],int length,int n) {int i=0; while (i<length&&a[i]!=n) {i++; } if (i>=length) {return 0; } else {return 1; }}//Main operations int mergelist (int a[],int &la,int b[],int lb) {int i=0; while (I<LB) {if (locate (A,la,b[i])) {i++; } else{_insert (a,la,b[i++]); }}}int Main () {int a[20],b[20]; int la,lb; Enter a length of a, while (CIN>>LA>>LB) {//MakeThe length of a is less than B if (la>lb) {swap (LA,LB);} Create (A,la);//Creation Order table A creates (b,lb);//create Order Table B mergelist (A,LA,B,LB); Show (A,la); }}
Set operation (A-B) U (B-A)