Create generic LinkedList and Node classes that implement the List interface(https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/List.html).
There is no specification regarding the design of the linked list, however it must function similar to those demonstrated in lectures. Null values are permitted within the list.
The majority of methods are unit tested individually, however the following methods will be used in the testing of others:
add(E e)
get(int index)
size()
clear()
The following methods will not be tested (and can return dummy values):
hashcode()
listIterator()
listIterator(int index)
E[] toArray(E[] a)
The list should be able to be constructed like so:
List myList = new LinkedList(); Notes
For the final toArray(E[] a)
method, use the following code:
JAVA1public X[] toArray(X[] a) {2 return null;3}
Because equals(Object o)
takes in an Object and not a List, create a new method public boolean equalsList(List o)
that has the same functionality as specified for equals(Object o)
in the javadoc. (Note that to test this method, LinkedList list = new LinkedList();
will be used, otherwise the new method will not be recognised)
You are only allow to import the following packages:
JAVA1import java.util.List;2import java.util.Iterator;3import java.lang.Iterable;4import java.util.Collection;5import java.util.ListIterator;6import java.util.NoSuchElementException;
Your program must compile without any warning messages from the compiler. Failure to do so will result in mark deductions.
You cannot use the instanceof
keyword in your code.