Create an empty set a of integers obtain from the user some


Assignment

1. Implement a generic class Set(T) that maintains a set of items of generic type T using the class LinkedList(T) in the Java API. Your Set class must provide the following instance methods:

add: that adds a new item. (Ignore if already in the set.) remove: that removes an item. (Ignore if not in the set.)

membership: that returns true if a given item is in the set and false otherwise.

toString: that returns a string with the list of the items in the set.

(REMINDER: do not violate encapsulation, you can only use List methods.)

2. Write a testSet class with a main() method that tests all the operations of the Set class above. That is, create an empty set A of integers, obtain from the user some integers and store some in A, some in B, and some in both, display the set using toString(), obtain from the user some integers and remove them from A using remove(), display the set using toString(), obtain an integer from the user and check whether it is in A or not using membership() and display the result. (REMINDER: you can only store objects.)

3. Based on the big-O running time of each method, argue whether implementing with ArrayList would have been better or not. (A complete answer must include the big-O running time of all methods for each of the implementations. If you do not base your answer on the big-O running time, you get no points.)

4. Expand your class Set(T) with the following static methods, and expand your testSet class to test them.

union: that returns the union of two given sets.

intersection: that returns the intersection of two given sets. difference: that returns the difference between two given sets.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Create an empty set a of integers obtain from the user some
Reference No:- TGS02556916

Expected delivery within 24 Hours