Computer Science, asked by sandeepsumantomar85, 1 month ago

Write a program in C to create two sets and perform the Difference operation on sets

Answers

Answered by om472846
0

Program:

#Include <iostream> #include<algorithm>

using namespace std;

int binary Search (int arri, int 1, int x); void printUnion(int arr1[], int arr20, int m, int n)

if(m>n)

int tempp = arr1;

arr1 = arr2;

arr2 = tempp: int temp = m;

m=n3B n=temp:

Sort(arr1, arrt + m); for ( int i=0; i<m; i++)

count << arr1[0] <<"";

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 = arrt:

arr1 = arr2: arr2 = tempp:

int temp = m;

m n; n= temp:

1 sort(arr1, arr1 +m):

for (int i=0; i<n;i++) if ( binarySearch (arr, 0, m-1, arr2[i]) !=-1) count << arr2[i] << "";

int binaryseach (int arr], int I, int r, int x)

if (r>=1)

int mid = 1 + (t-1)/2

if (arr[mid) == x) return mid;

iffartſmid]>x)

return binary Search (arr, I, mid-1, x);

return binary Search (arr, mid+1, r, x);

return -1;

int main()

int arr[] = (7, 1, 5, 2, 3, 6);

int arr2[] = (3, 8, 6, 20, 7);

int m = sizeof (arry/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 3678 20152

Intersection of two arrays is

736

Similar questions