Skip to content

Latest commit

 

History

History
14 lines (10 loc) · 873 Bytes

a6e7.md

File metadata and controls

14 lines (10 loc) · 873 Bytes

Back to questions

Solution to a6e7: Int set iterators

See code at solutions/code/tutorialquestions/questiona6e7

The way iterators can be implemented for this question are exactly analogous to the methods demonstrated in the solution to question 1486. Again, I have provided three versions using standard classes, inner classes and anonymous inner classes.

The interesting parts of this question are Steps 3 and 4. Look at the AbstractIntSet class (in any of the solution versions) to see that the iterator facilities provided by an IntSet allow us to implement algorithms to check containment, remove one set from another, add one set to another, and turn a set into a string, at the abstract level. We do not need to implement separate algorithms for MemoryEfficientIntSet and SpeedEfficientIntSet.