logo Practice-It logo

equals

Language/Type: Java Stacks and Queues
Author: Jeff Prouty (on 2020/10/22)

Write a method called equals that takes two sets of integers as parameters and that returns true if the sets are equal. Two sets are considered equal if they store the same values. For example, given sets: s1: [5, 3, 1, 0] s2: [0, 1, 5, 3] s3: [1, 0, 5, 3, 4] The call equals(s1, s2) would return true while the calls equals(s1, s3) and equals(s2, s3) would return false. As in the examples above, you can not assume that the set values are ordered.

You are implementing a two-argument alternative to the standard Set method called equals, so you are not allowed to call that method or the containsAll method to solve this problem. You may construct iterator objects, but you are also not allowed to construct any structured objects to solve the problem (no set, list, stack, queue, string, etc). Your method should not change either of the sets passed as parameters.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.