A09

Due Date: Thursday, March 26
File(s) to be submitted: TreeMapBag.java
Sample Output: SampleOutput.html
Starter Files:


SUBMIT   /   Check

TreeMapBag (Implementing Bag Using a java.util Class

Summary

In this assignment you will implement the Bag interface using a java.util.TreeMap.

NOTE: this is not the TreeBag class from the notes, tho' you may find some of the methods from that class helpful for your implementation.

Your implementation does not need to include iterator, but should include the containsAll, addAll, removeAll and retainAll methods.

Details

The ArrayBag and LinkedBag classes that we created earlier in the course went "back to basics" in order to help you understand how the ArrayList and LinkedList classes are implemented, and also to get a feel for why some data structures are good at some operations and worse at others.

But in general it is better to use the tools that Java provides to produce the results you need.

In this assignment you are going to use Java's TreeMap class to implement the Bag interface.

In the notes you will see a partial implementation of a TreeBag class. Your TreeMapBag class will operate in much the same way, but will use java.util's built in type to avoid some of the complicated programming necessary for making a balanced binary search tree.

In particular:

Your TreeMapBag class must have two constructors:

To help you along, here are some notes on TreeMaps:


SUBMIT   /   Check