# Set operation (A-B) U (B-A)

Source: Internet
Author: User

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&LT;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&GT;&GT;LA&GT;&GT;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)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.