+ 2
Do you possess satisfactory knowledge of Sets? In union, the new set = set a + set b elements (Common or not). So we add the arrays by storing in a new array. First we copy the first set a, then the set b. This way, we are able to store the union. for(i=0; i<m; i++)  { R[i] = A[i]; l++; } //Copying set 1. int e = l; for(i=0; i<n; i++)  { int found=0; /* Now, found is used to check if we are accidently copying a number again from set 2 thats already copied from set 1. Thus, its a marker */ for(int j=0; j<e; j++)  { if (B[i] == R[j]) //If we have a match in our data... { found = 1; break; } } //Don't copy that element. if (found==0) //Otherwise... { R[l] = B[i]; l++; } } //Copy it and increase the size.
4th Oct 2017, 1:41 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar