Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE JAVA A set is a collection of elements in which no element occurs more than once (distinct elements). We can implement a simple

PLEASE USE 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).

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.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.

MyList.java Interface

interface MyList { public void clear(); public boolean isEmpty(); public boolean contains(E object); public int indexOf(E object); public E get (int index); public int set (E object, int index); public int size(); public void add(int index, E object); public E remove(int index);

}

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

Students also viewed these Databases questions

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago