equals
method for OurLinkedList
Implement a method equals
in OurLinkedList
class
that takes an object and returns true if that object is an instance of
OurLinkedList
and has the exact same elements (as given by
calling equals
method on the respective elements) in the
same order and false otherwise. If two lists are of different size,
the method returns false. You may assume that your list does not
contain null elements.
You can use your own OurLinkedList
implementation, or just
the starting code
here since you only need an
add
method to test equals
.
Test your method well and submit all of your testing code.
This problem is loosely based on Problem 14 on p. 239 and asks you to implement and test a class Set<E>. A set should work according to the mathematical definition of a set. A few requirements and details:
equals
returns true for them.
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.
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 (but be
careful not to add elements that are already in the set).toString
returns a string representation of a Set.
contains(E element)
returns true if an element is
present in the set and false otherwise. Use equals
to
determine if two elements are the same.
union(Set<E> otherSet, Set<E> resultSet)
which makes resultSet
to be the union of the two sets. If
resultSet
isn't empty, it is first made empty, and then
the elements of the union are added to it.
Set<String>
or Set<Integer>
) inside the Set class.
intersection(Set<E> otherSet, Set<E> resultSet)
which makes resultSet
to be the intersection of the
two sets. If
resultSet
isn't empty, it is first made empty, and then
the elements of the union are added to it.
removeAll()
removes all elements from the set.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.