c program for create two sets and perform difference operation on sets
Answers
Explanation:
Write a program to perform Set operations :- Union, Intersection, Difference,Symmetric ... Created By : JABIR DAUD PATHAN ..... Symmetric Difference of Two ...
The given program is used the two sets with the two different operation as union and intersection.
Program:
#Include <iostream>
#include<algorithm>
using namespace std;
int binarySearch (int arr[], int 1, int x);
void printUnion(int arr1[], int arr2[], int m, int n)
{
if(m>n)
{
int * tempp = arr1;
arr1 = arr2;
arr2 = tempp;
int temp = m;
m=n;
n=temp;
}
Sort(arr1, arr1 + m);
for ( int i=0; i<m; i++)
count << arr1[i] <<"";
for (int i=0; i<n; i++)
if (binarySearch(arr1, 0, m-1, arr2 [i]) == -1)
count<< arr2[i] << "";
}
void printIntersection(int arr1[], arr2[], int m, int n)
{
if (m>n)
{
int *tempp = arr1;
arr1 = arr2;
arr2 = tempp;
int temp = m;
m = n;
n = temp;
}
sort(arr1, arr1 +m);
for (int i=0; i<n;i++)
if ( binarySearch (arr1, 0, m-1, arr2[i]) !=-1)
count << arr2[i] << "";
}
int binaryseach (int arr[], int l, int r, int x)
{
if (r >=1)
{
int mid = 1 + (r-1)/2;
if (arr[mid] == x) return mid;
if(arr[mid]>x)
return binarySearch (arr, l, mid-1, x);
return binarySearch (arr, mid+1, r, x);
}
return -1;
}
int main()
{
int arr1[] = {7, 1, 5, 2, 3, 6};
int arr2[] = {3, 8, 6, 20, 7};
int m = sizeof (arr1)/sizeof(arr1[0]);
int n =sizeof(arr2)/sizeof(arr2[0]);
count<< "union of two arrays is n";
printUnion(arr1, arr2, m, n);
count<< "nIntersection of two arrays is n";
printIntersection(arr1, arr2, m, n)
return 0;
}
OUTPUT
Union od two array is
3 6 7 8 20 1 5 2
Intersection of two arrays is
7 3 6
To Learn More...
https://brainly.in/question/12575282