COMP2000 - Data Structures Fall 2020 DLList Iterator Completion Due: Sep 25, 2020 at 11:59PM 1 DLList Iterator Completion Specification 1.1 Available Resources • Lecture slides/video • Other sections...

1 answer below »
need help with the data structure assignment. i have provided the assignment and the skeleton code. and you just have to follow the instructions


COMP2000 - Data Structures Fall 2020 DLList Iterator Completion Due: Sep 25, 2020 at 11:59PM 1 DLList Iterator Completion Specification 1.1 Available Resources • Lecture slides/video • Other sections of the provided code • me: [email protected] or discord. (If you have a general question, feel free to post in #class-chat) • The textbook • DO NOT refer to or use online implementations 1.2 Lab Instructions • This is an individual lab. • Make sure to read through all of the specifications so your submission is complete. • Follow all the submission steps in the Setup document by the lab deadline. 1.3 Lab Link The skeleton code for the lab is available at https://classroom.github.com/a/s3n2lFQS. 1.4 Implementation This lab introduces a DLList class to implement a list. The list can only be modified using a ListIterator – all of the class methods of the List are gone. Note the class header: DLList implements Iterable. This promises that DLList has an iterator() function. In addition, an inner class KWListIter implements ListIterator is defined. ListIterator is an extension of Iterator, with more specific operations available. The tests class has many examples that use this iterator. I have provided the class code in the edu.wit.cs.comp2000 package. You will implement the remaining method – set. Descriptions of all of the method’s expected behavior are included in the lecture slides (on the ListIterator page). In addition, Javadoc comments for them are visible if you hover over the method names in Eclipse, as they implement the ListIterator interface. For your implementation, consider what effect the method should have on the data structure. 1.5 Testing The other goal of this lab is to practice with more unit testing and debugging. We will use this framework this semester to verify that our data structure implementations work the way we expect them to. In addition to the DLList code, JUnit tests are provided in the edu.wit.cs.comp2000.tests package. You can run these tests to see if the DLList implementation is performing correctly. The tests that I have provided check that most of the iterator operations are behaving as expected. They also provide examples of how the JUnit methods assertTrue and assertEquals work and examples of how expected exceptions can be detected. For the rest of the provided test methods (the ones that fail as not implemented), implement tests that check if that method works with the list implementation. You can follow the steps that other test methods take for each test – create a list and iterator, modify the list, and then assert the ListIterator behaves the way you expect. Make sure that you actually call the ListIterator method that you are testing. 1 of 2 https://classroom.github.com/a/s3n2lFQS COMP2000 - Data Structures Fall 2020 DLList Iterator Completion Due: Sep 25, 2020 at 11:59PM 1.6 Debugging One of the iterator methods has an error in it! It works in some situations but not others. Using the JUnit tests and your knowledge of the operation, fix that method in DLList so that it works correctly in every case. Think about which cases it currently covers, and which cases it’s missing. Change the code so that it covers all of the cases correctly. Once you do, the unit tests should correctly pass for it. 1.7 JUnit Assertion Syntax For each of the JUnit assert* methods, the first argument is the string that prints out if the test fails. Use any of these four assert methods in your tests to confirm the functionality of the SLList methods: • assertTrue • assertEquals • assertNotEquals • assertNull 1.8 Considerations For Each Method Be considerate in testing your ADT. Your goal is to test all of the possible cases for each DLList method. Each test method may have several assert method calls depending on how many possibilities you test for. In future labs, you will be writing more complete test cases like these to test your own code. 1.8.1 Common Edge Cases How might our list be structured when we run an operation? Consider all the different possibilities for each operation. For each case that applies, we will want to write some code that sets up a list, followed by at least one assert statement. • Normal results (no bad inputs, no special cases in the operation) • Bad input index • Adding/removing data from the front or end • Expecting an exception 2 Double Check: • Have you implemented the set ListIterator method? • Have you written two JUnit tests? • Have you debugged the DLList code so all the tests pass? • Have you committed/pushed your code from the two files? 3 Grading Each of the 4 TODO sections is worth 14 of the lab grade. Grades and any comments for the lab will be posted to your project on github. Grades will also be posted to Blackboard, eventually. 2 of 2 DLList Iterator Completion Specification Available Resources Lab Instructions Lab Link Implementation Testing Debugging JUnit Assertion Syntax Considerations For Each Method Common Edge Cases Double Check: Grading So here is the skeleton code provided: 1) DLLIST: package edu.wit.cs.comp2000; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; /** Class to represent a linked list with a link from each node to the next node. */ public class DLList implements Iterable { /** Reference to list head. */ private Node head = null; /** Reference to list tail. */ private Node tail = null; /** The number of items in the list */ private int size = 0; @Override public Iterator iterator() { return new KWListIter(); } public ListIterator listIterator() { return new KWListIter(); } /** A Node is the building block for a singleâ€linked list. */ private static class Node { // Data Fields /** The reference to the data. */ private E data; /** The reference to the next node. */ private Node next; /** The reference to the previous node. */ private Node prev; // Constructors /** Creates a new node with a null next field. @param dataItem The data stored */ private Node(E dataItem) { data = dataItem; next = null; prev = null; } /** Creates a new node that references another node. @param dataItem The data stored @param nextRef The node referenced by new node @param prevRef The node before the new node */ private Node(E dataItem, Node nextRef, Node prevRef) { data = dataItem; next = nextRef; prev = prevRef; } } private class KWListIter implements ListIterator { private Node nextItem; private Node lastItemReturned; private int index; public KWListIter() { lastItemReturned = null; nextItem = head; index = 0; } public KWListIter(int i) { // Validate i parameter. if (i < 0="" ||="" i=""> size) throw new IndexOutOfBoundsException("Error: " + i); lastItemReturned = null; // No item returned yet. // Special case of last item if (i == size) { index = size; nextItem = null; } else { // Start at the beginning nextItem = head; for (index = 0; index < i; index++) nextitem = nextitem.next; } } public boolean hasnext() { return nextitem != null; } public e next() { if (!hasnext()) i;="" index++)="" nextitem="nextItem.next;" }="" }="" public="" boolean="" hasnext()="" {="" return="" nextitem="" !="null;" }="" public="" e="" next()="" {="" if="">
Answered Same DayOct 03, 2021

Answer To: COMP2000 - Data Structures Fall 2020 DLList Iterator Completion Due: Sep 25, 2020 at 11:59PM 1...

Arun Shankar answered on Oct 05 2021
136 Votes
// package edu.wit.cs.comp2000;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
/** Class to represent
a linked list with a link from each node to the next node.
*/
public class DLList implements Iterable {
    /** Reference to list head. */
    private Node head = null;
    /** Reference to list tail. */
    private Node tail = null;
    /** The number of items in the list */
    private int size = 0;
    
    
    
    @Override
    public Iterator iterator() {
        return new KWListIter();
    }
    public ListIterator listIterator() {
        return new KWListIter();
    }
    /** A Node is the building block for a single‐linked list. */
    private static class Node {
        // Data Fields
        /** The reference to the data. */
        private E data;
        /** The reference to the next node. */
        private Node next;
        /** The reference to the previous node. */
        private Node prev;
        // Constructors
        /** Creates a new node with a null next field.
         @param dataItem The data stored
         */
        private Node(E dataItem) {
            data = dataItem;
            next = null;
            prev = null;
        }
        /** Creates a new node that references another node.
         @param dataItem The data stored
         @param nextRef The node referenced by new node
         @param prevRef The node before the new node
         */
        private Node(E dataItem, Node nextRef, Node prevRef) {
            data = dataItem;
            next = nextRef;
            prev = prevRef;
        }
    }
    private class KWListIter implements ListIterator {
        private Node nextItem;
        private Node ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here