logo Practice-It logo

removeSorted

Language/Type: Java Collections Sets and Maps
Author: Marty Stepp (on 04/02)

Write a method called removeSorted that takes a set of Point objects as a parameter and that removes the points from the set whose x/y coordinates are in sorted order (points whose x-value is less than or equal to its y-value), returning a set of the removed Point objects. For example, if a set called points contains the following values:

        [[x=6,y=3], [x=9,y=7], [x=1,y=3], [x=7,y=7], [x=3,y=2], [x=4,y=3],
         [x=3,y=4], [x=-3,y=8], [x=108,y=15], [x=125,y=482], [x=1,y=42]] 

then the call removeSorted(points) should leave the set storing:

        [[x=6,y=3], [x=9,y=7], [x=3,y=2], [x=4,y=3], [x=108,y=15]]

and the set returned should store the following values:

        [[x=1,y=3], [x=7,y=7], [x=3,y=4], [x=-3,y=8], [x=125,y=482],
         [x=1,y=42]]

The values in the returned set can appear in any order.

You may construct iterators and the set to be returned, but you are not allowed to construct other structured objects (no string, set, list, etc.).

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.