CMSC204 Assignment 3-Double Linked Lists Solved

30.00 $

Category:

Description

5/5 - (1 vote)

Your assignment is to write a generic double singly-linked list class with an iterator, and a generic sorted double singly-linked list class with an iterator that inherits from your generic double singly-linked list class. The GUI has been provided for you for this assignment to help you visualize your linked list. Your list classes will also be tested with Junit tests. Upload the initial files from Blackboard and your working files in a directory into the repository in GitHub you created in Lab 1 and take a screen shot of the files.

Concepts tested by this assignment

 

Exception handling

Generic Classes

Double Linked List

Ordered Double Linked List

Iterators

Comparators

Classes

BasicDoubleLinkedList

This generic double singly-linked list relies on a head (reference to first element of the list) and tail (reference to the last element of the list). Both the head and the tail are set to null when the list is empty. Both point to the same element when there is only one element in the list, and now the element’s “next” and “previous” references point to null. A node structure has only two fields: data and the 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 are you 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.

SortedDoubleLinkedList

A generic sorted double linked list will be constructed using a provided Comparator to determine how the list is to be sorted.  It extends BasicDoubleLinkedList class.  The addToFront and the addToEnd methods will not be supported and an add method will be added that inserts to the double linked list in sorted order dependent on the Comparator. 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 SortedDoubleLinkedList 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.

GUI driver (provided for you)

          A GUI driver has been provided for you to help you visualize your doubly-linked lists. Here is the minimum that must be in place to start using the GUI driver effectively.

  • All methods in your BasicDoubleLinkedList and SortedDoubleLinkedList must be stubbed.
  • The addToFront or addToEnd method of the BasicDoubleLinkedList must be implemented to create a basic double singly-linked list.
  • The add method of the SortedDoubleLinkedList must be implemented to create a sorted double singly-linked list.
  • The toArrayList method in both the BasicDoubleLinkedList and SortedDoubleLinkedList, which returns an arraylist of the items in the list from the head of list to the tail of list. This method is used to display the contents of the lists.

Testing

  1. Your code should cause the BasicDoubleLinkedList_Test tests to succeed.
  2. Your code should cause the SortedDoubleLinkedList_Test tests to succeed.
  3. Create a JUnit Test – Basic
  4. Create a JUnit Test – SortedDoubleLinkedList_STUDENT_Test.
Examples using GUI driver

 

Adding to a Basic List                                                                                   Adding to a Sorted List

Removing Second from basic                                               Removing Thomas from sorted

start the iterators for Basic and Sorted. Think of iterators being “in between” nodes.

Example of selecting “Next” for Basic and then for Sorted list. Think of iterators being “in between” nodes.

Example of “Next” for basic and “Previous” for Sorted. Think of iterators being “in between” nodes.

 

  • Assignment3-7bpo3z.zip