Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Understanding inner classes , needed for clean HashSet/HashMap implementations and other container classes. Consider again Bag.java on page 155, but this time let's keep the
- Understanding inner classes, needed for clean HashSet/HashMap implementations and other container classes. Consider again Bag.java on page 155, but this time let's keep the Nodes and see how they work. Note that the "private" inside the nested class ListIterator is ineffective and would be better removed. Also note that ListIterator is not a JDK ListIterator at all.
- Consider the Bag with "apple", "banana", "pear" added in that order. Draw the Bag object using the same boxes as shown on slide 6 of Feb.18, i.e, the same format as used in problem 1. Hand-drawn is fine. You can show the string objects hanging off or put the string values in boxes in the Node as done there.
- Suppose a ListIterator object has just been created by Iterator itr = bag.iterator(), in client code to Bag, where bag is the Bag of 3 strings described in part a. This new object itr is separate from the bag object, but its current instance variable references the bag's very first Node object. To the client, itr's type is simply Iterator, no hints of its concrete type (and no downcasts allowed either: that ListIterator type is private to Bag). Draw an object diagram showing these two objects (itr and bag) and their references.
- Suppose itr.next() is called. Draw the new object diagram.
- Can a single Bag object like bag have two iterators existing at the same time? Explain how or why not.
============================================================================================================================================== Here is the format for the problem, pls draw the diagram. thank you
ALGORITHM 1.4 Bag import java.util.Iterator; public class BagStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started