value_type data[CAPACITY] |
The set ctor declares set objects with an array of int's size 30 (== CAPACITY) but upon initialization this array is just filled with garbage values, so it would be useful for the set class to have another variable:
that would go ++elements upon each insert() and --elements upon each remove(), subject to upper(CAPACITY) and lower(0) boundaries, to keep track of how many actual elements are there in each set.
Then for set_intersection() start with (a) the set that has the fewer elements and (b) a declared set object setIntersect.
For each element in the set that has fewer elements check if this elements exists in the other set. If yes, insert this element into setInsersect ... return setIntersect
set_difference(): to get A - B you'd check each element of A to see if it was present in B, if not then that element is a candidate for A - B, so insert this element into another locally declared set setDifference ... return setDifference
is_subset() - you should be able to have a go at this one if you can make set_intersection() work
1 2 3 4 5 6 7 8
|
std::ostream& operator << (std::ostream& output, const set& s)
{
for (size_type t = 0; t < elements; ++t)
output << (s.getdata())[t] << " ";
//where getdata() is the getter for private member data of const set object s
//again print only upto elements, not CAPACITY
return output;
}
|