QuestionQuestion

In Lab 3 your task is to create an endless circular doubly linked list. It must be generic, implement all of the above methods, and provide an iterator. Be sure to add proper method comments. In addition to this, you must create a JUnit test class that tests all of the methods and the iterator.
In the Lab 3 module you are given a NetBeans project that contains the following classes:
• A completed Node class.
• An EndlessList class that implements the above data structure. (The methods in this class are currently just stubs.)
Your job is to complete the EndlessList class, create a JUnit test class, and thoroughly test EndlessList.
The following requirements and limitations apply:
• You must make the EndlessList class generic so that it accepts any type of object.
• You must provide an iterator for EndlessList.
• You may not use any existing collection structure – the whole point is to write your own.
• You may not implement indices internally in EndlessList – work through the references in the
nodes to move from one value to the next.
• You may not alter or add anything to the code other than to write the methods marked with TODO comments.
• You should have NetBeans create the test file for you, but add or modify test methods as necessary to assure 100% coverage – be sure to cover all iterator and node methods, too.
Note that when a value is first added to the list, its previous and next references will be to itself. There should never be a node with a null prev or next field.
Also note that the iterator should iterate over the entire list without repeating the loop. It should also handle correctly if the first node is removed by the iterator remove method.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

package ;

import java.util.Iterator;

/**
* This data class represents an ordered collection in an endless circular list.
*
* @param <E> the type of values stored in the list
* @author
* @author
* @author
* @author
*/
public class EndlessList<E> implements Iterable<E> {

    //fields
    private Node<E> cursor;

    /**
    *
    */
    public void addPrev(E value) {
       // TODO write method body //
       Node<E> n = new Node(value, null, null);
       /**
         * Note that when a value is first added to the list, its previous and
         * next references will be to itself. There should never bea node with a
         * null prev or next field.
         */
       n.setNext(n);
       n.setPrev(n);

       /**
         * adds the value right before the current one and moves the cursor to
         * the new node, or if cursor is null make the value the cursor
         */
       if (cursor != null) {
            n.setNext(cursor);
            n.setPrev(cursor.getPrev());

            n.getPrev().setNext(n);
            cursor.setPrev(n);

       }
       cursor = n;
    }

    /**
    *
    */
    public void addNext(E value) {
       // TODO write method body //
       Node<E> n = new Node(value, null, null);
       /**
         * Note that when a value is first added to the list, its previous and
         * next references will be to itself. There should never bea node with a
         * null prev or next field.
         */
       n.setNext(n);
       n.setPrev(n);

       /**
         * –adds the value right after the current one and moves the cursor to
         * the new node, or if the cursor is null make the value the cursor
         */
       if (cursor...
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats