/********************************************************************************************************* ** Description: Calculates the intersection of two or more sets, returning the set that represents ** that intersection. **********************************************************************************************************/ IntSet IntSet::getIntersection(const IntSet& obj) const { IntSet interSet; for (int i = 0; i < obj.size(); i++) //loop through the set given as an argument { if (this->contains(obj.set[i])) //if the calling set contains the argument's current element... { interSet.add(obj.set[i]); //add that element to the intersection set } } return interSet; //return the intersection }
/********************************************************************************************************* ** Description: Calculates the union of two or more sets, returning the set that represents that union. **********************************************************************************************************/ IntSet IntSet::getUnion(const IntSet& obj) const { IntSet unionSet = *this; //initialize a new set with the elements of the calling set for (int i = 0; i < obj.size(); i++) //loop through the set given as an argument { if (!unionSet.contains(obj.set[i])) //if the current element is not already in the union set... { unionSet.add(obj.set[i]); //add that element to the union set } } return unionSet; //return the union }