Question: 1. Implement (using an array) an ADT Set of integers that supports the following operations: +Set() /constructor that creates an empty set +isEmpty() : Boolean

1. Implement (using an array) an ADT Set of integers that supports the following operations:

+Set() /constructor that creates an empty set +isEmpty() : Boolean /Determines whether a set is empty +size() : integer /Returns the cardinality of the set +add(in item : integer) /Adds the specified element to this set if it is not already present +contains(in item : integer) : Boolean /Determines if this set contains the specified item +union(in other : Set) : Set /Creates a new set containing all of the elements of this set and the other set (no duplicates) and returns the resulting set +intersection(in other : Set) : Set /Creates a new set of elements that appear in both this set and the other set and returns the resulting set +removeAll() /Removes all of the items in the set 2. Contain a class attribute called setArray that is an array of integers of length 10 and a class attribute called size that is initialized to 0. 3. On each call to add, check to see if setArray is full. If adding the new element would cause the array to overflow, then a. create a new larger array that is twice the size of the original array b. copy the contents of the original array to the new array c. add the new element to the new array d. reassign setArray to reference the new array e. increment the size attribute 4. The implementation should reset the size of setArray back to 10 if all the elements are removed (i.e. removeAll() is called).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!