logo CodeStepByStep logo

HashSetAddAll

Related Links:

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 Practice-It and avoid conflicting with Java's java.util.HashSet, our HashSet is renamed HashSet2 here.)

Partial class: Write code that will become part of an existing class as described. You do not need to write the complete class, just the portion described in the exercise.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.