Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions