Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment1: Implementing Sets MUST BE DONE WITH JAVA A set is a collection of elements in which no element occurs more than once (distinct elements).

Assignment1: Implementing Sets

MUST BE DONE WITH JAVA

A set is a collection of elements in which no element occurs more than once (distinct elements). We can implement a simple set as a linked list to store the items in the set.

Fundamental Set operations are add(E element), remove(E element), union(Set otherSet), intersection(Set otherSet) and difference(Set otherSet)

Implement the MySet class as depicted by the figure below.

Node

Element: E

Next: Node

------------------------------------------------------

<> MyList

^^^^^^^^^^^^^^^^^^^^^

MySet

head

tail

size

+ MySet()

+ MySet(arr : E[])

+ MySet(otherList : List)

+ Boolean Add(element:E): boolean

+ Boolean Remove(element:E): boolean

+ union(otherSet: MySet): MySet

+ intersection(otherSet: MySet): MySet

+ difference(otherSet: MySet): MySet

The class should implement the MyList interface (all abstract methods defined in MyList should be implemented in MySet) and should contain three constructors to create an empty set, create a set from an array of objects or create a set from a List (ArrayList, LinkedList).

Define and implement the following methods in MySet:

Boolean add(E element) : add element to the set, return true if element is added

Boolean remove(E element): remove element from the set, return true if element is found and removed

MySet union(MySet otherSet): return a set containing elements from both sets

MySet Intersection(MySet otherSet): return the intersection of two sets

MySet Difference(MySet otherSet): return the difference of two sets

Write a test program that creates Three MySet instances, set1, set2 and set3 and show that the three constructors and all methods implemented in MySet class are working properly.

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

ISBN: 1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago