Requirement #2: Implementthe java.util.IteratorInterface The java.util.Iterator
ID: 3610331 • Letter: R
Question
Requirement #2: Implementthe java.util.IteratorInterface
The java.util.Iterator interfaceis defined on-line at java.sun.com.You must implement an Iterator thatwill iterate over the items stored in your AVL tree. You couldimplement your Iterator using aclass that is nested inside of the class you use to implementjava.util.Set.
You must fully implement the following methods:
boolean hasNext()
Object next()
Your implementation is allowed to throw UnsupportedOperationException for thefollowing method:
void remove()
Your implementation must conform to the required behavior ofeach method as defined in the on-line documentation. The definitionof java.util.Set allows anIterator to return the items in theset in any order. Your implementation must meet an additionalrequirement. You must return the items in the order given by apreorder traversal of the AVL tree that is implementing theset. The order in which items are returned from the Iterator will be used to determine if yourtree is constructed and balanced correctly.
The iterator method in the classthat implements java.util.Setshould return an Iterator object asdescribed in this section.
The toArray method in the classthat implements java.util.Set mustfill its array in the same order as described here for theIterator. In fact, you could use anIterator to help implement the toArray method.
Explanation / Answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.