Suppose that we want to implement the ADT set. Recall from Project 1 of Chapter 1 that a set is an unordered collection of objects where duplicates are not allowed. The operations that a set should support are
• Add a given object to the set
• Remove a given object from the set
• See whether the set contains a given object
• Clear all objects from the set
• Get the number of objects in the set
• Return an iterator to the set
• Return a set that combines the items in two sets (the union)
• Return a set of those items that occur in both of two sets (the intersection)
Define a class Set that uses a dictionary internally to implement these operations.
As we mentioned in Segment 1.21, a set is a special bag that does not allow duplicates.
a. Specify each operation for a set of objects by stating its purpose; by describing its parameters; and by writing preconditions, postconditions, and a pseudocode version of its header. Then write a Java interface, SetInterface
, for the set. Include javadoc-style comments in your code. b. Suppose the class Set
implements SetInterface . Given an empty set that is an object of Set and an object of the class Bag that contains several strings, write statements at the client level that create a set from the given bag.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.