Problem 14 on p. 239 specifies methods and behavior of a set. Implement and test a class Set<E> with the following differences from the one described in the book:
Set<E>
, where E is
the type of the elements in the set. For instance, you would be able
to create Set<String>
or Set<Integer>
. All methods that take or
return elements should take or return objects of type E.ArrayList
, and not an array, to
store the elements. createSet
just write a
constructor that creates an empty set, i.e. you should be able to
create a set of strings as new Set<String>()
isEmpty()
that returns true if this set is empty and
false otherwise,size()
that returns the size of the set (the number
of elements)add(E element)
adds an element to a set if it's not
already present.contains(E element)
returns true if an element is present in
the set and false otherwise.union(Set<E> otherSet)
returns a
new Set<E>
that is the
union of this set and the other set. Make sure you follow definition
of set union.intersection(Set<E> otherSet)
returns a
new Set<E>
that is the
intersection of this set and the other set. Make sure you follow definition
of set intersection.removeAll()
removes all elements from the set.Use test-first development for this problem: write JUnit tests first, then implement the feature, then write a JUnit test for the next feature, etc. Submit your Set class and your JUnit class. The quality of your testing will be a part of the grade.
Use the same setup that we have used for Insertion sort and Quicksort to implement
Comb sort. Comb sort sorts
the array by choosing a gap and sorting subsets of elements at the gap distance using bubble sort.
Then the gap gets reduced, and the process is repeated. It stops when the gap is reduced to 1, at
which point just the regular bubble sort is performed.
The rationale behind this approach is to quickly eliminate small values (known as "turtles") near the end
of the array since they slow down the bubble sort.
Submit your Java file(s) to me by e-mail. The subject must be Problem Set N, where N is the problem set number. If working in a group, CC your group partner.