Question: Your assignment is to write a generic doubly-linked list class and a generic sorted doubly-linked list class that inherits from your generic doubly-linked class. There
Your assignment is to write a generic doubly-linked list class and a generic sorted doubly-linked list class that inherits from your generic doubly-linked class. There is no additional GUI required for this assignment. Your list classes will be tested with Junit tests.
BasicDoubleLinkedList class
This generic doubly-linked list relies on a head (reference to first element of the list) and tail (reference to the last element of the list). Both are set to null when the list is empty. Both point to the same element when there is only one element in the list. A node structure has only three fields: data and the prev and next references. The class must only define the following entities: an inner class Node, an inner class that implements ListIterator (for the iterator method), head and tail references and an integer representing the list size. However only the next(), hasNext(), previous() and hasPrevious() methods of the ListIterator that you are required to implement. The rest of the methods can throw the UnsupportedOperationException, such as:
public void remove() throws UnsupportedOperationException{
throw new UnsupportedOperationException();}
All the entities are defined as protected so they can be accessed by the subclass. Follow the Javadoc that is provided.
Exception Handling
UnsupportedOperationException this exception is a Java library exception and will be returned by the addtoFront and addToEnd implementations of the SortedLinkedList class and by the remove method of the iterator.
NoSuchElementException this exception is a Java library exception and will be returned by the next function within the iterator class when there are no more elements in the linked list.
ointerface Listlterator Node # data: T # prev: Node # next: Node + hasrevusbooiean + next:T +hasPrevious):booean + previou):F + remover): void + addargd: T void +Node(dataNode: T) inner class0..* + previousindex:t +setfargo: ): void Following methods are to be implemented: public boolean hasNext) public boclean hasPrevious() public T nextO public T previous) Following methods are to throw an UnsupportedOperationException: public void remove) public void add(T arg0) BasicDoubleLinkedList DoubleLinkedListlterator # head: Node # tal: Node # size: int ----public int nextIndex) public int previousindex) public void set(T arg) + iterator): Listterator + addToEnd(data: T): BasicDoubleLinkedist + addToFront(data: T) : BasicDoubleLinkedList + getFirst):T + getlast):T + getSize): int + removestargetData: T, comparator: Comparator) BasicDoubleLinkedList iterator: returns an instance of inner class DoubleLinkedListlterator that implements ListIterator addToEnd: Adds an element to the end of the ist addToFront: Adds an element to the front of the lst getFirst: Return but do not remove the first element from the list. - --getLast: Return but do not remove the last element from the list. getsize: Get the ist size from the size field remove: Remove the first instance of the suppied argument from the list. Use the provided comparator to find those elaments that match the target retrieveFirstElement: Remove and return the first element from the ist retrievelastElement: Remove and return the last element from the list.... + toArrayList): ArrayList SortedDoubleLinkedList iterator: call the super class terator method add: put the supplied data in the correct position in the list addToEnd: invalid for a sorted list I . +iterator) :ListIberator +add(data: T: SortedDoubleLinkedList +addToFront(data: T): BasicDoubleLinked ist +remove(data: T, comparator: Comparator ): SortedDoubleLinkedList addToFront: invalid for a sorted list remove: Implement by cling the super class remove method all other methods are inherited from BasicDoubleLinkedist class ointerface Listlterator Node # data: T # prev: Node # next: Node + hasrevusbooiean + next:T +hasPrevious):booean + previou):F + remover): void + addargd: T void +Node(dataNode: T) inner class0..* + previousindex:t +setfargo: ): void Following methods are to be implemented: public boolean hasNext) public boclean hasPrevious() public T nextO public T previous) Following methods are to throw an UnsupportedOperationException: public void remove) public void add(T arg0) BasicDoubleLinkedList DoubleLinkedListlterator # head: Node # tal: Node # size: int ----public int nextIndex) public int previousindex) public void set(T arg) + iterator): Listterator + addToEnd(data: T): BasicDoubleLinkedist + addToFront(data: T) : BasicDoubleLinkedList + getFirst):T + getlast):T + getSize): int + removestargetData: T, comparator: Comparator) BasicDoubleLinkedList iterator: returns an instance of inner class DoubleLinkedListlterator that implements ListIterator addToEnd: Adds an element to the end of the ist addToFront: Adds an element to the front of the lst getFirst: Return but do not remove the first element from the list. - --getLast: Return but do not remove the last element from the list. getsize: Get the ist size from the size field remove: Remove the first instance of the suppied argument from the list. Use the provided comparator to find those elaments that match the target retrieveFirstElement: Remove and return the first element from the ist retrievelastElement: Remove and return the last element from the list.... + toArrayList): ArrayList SortedDoubleLinkedList iterator: call the super class terator method add: put the supplied data in the correct position in the list addToEnd: invalid for a sorted list I . +iterator) :ListIberator +add(data: T: SortedDoubleLinkedList +addToFront(data: T): BasicDoubleLinked ist +remove(data: T, comparator: Comparator ): SortedDoubleLinkedList addToFront: invalid for a sorted list remove: Implement by cling the super class remove method all other methods are inherited from BasicDoubleLinkedist class