Originally Posted by
We'reGeeks
Combining all the elements of any two sets is called the Union of those sets. So for instance, given set1: {1,2,3} and set2: {345}, union : {1,2,3,4,5}. Right?
So here's my algorithm:
Compare ith element of set 2 with each elements of set 1. For as long as the ith element in set2 does not equal to any element in set1, ith element is stored in the array 'result' (as part of the union). When all elements of set 2 have each been compared to all elements of set 1, see if there are still elements in set 1 that have not been stored in 'result' and add them directly to 'result'.