Write a method named addAll
that could be placed inside the HashSet2
class.
This method accepts another HashSet2
as a parameter and adds all elements from that set into the current set, if they are not already present.
For example, if a set s1
contains [a, b, c]
and another set s2
contains [a, x, c, z]
, the call of s1.addAll(s2);
would change s1
to store [a, b, c, x, z]
in some order.
You are allowed to call methods on your set and/or the other set.
Do not modify the set passed in.
This method should run in O(N) time where N is the number of elements in the parameter set passed in.
(NOTE: To be compatible with our site and avoid conflicting with Java's java.util.HashSet
, our HashSet
is renamed HashSet2
here.)