Question: ---------------------------------------------------------------------------------------------------------- // File: A2SimpleDriver.java // Author: (your name here) / Rita Ester // Date: September 23, 2017 // Description: Basic test driver for CSCI 225


----------------------------------------------------------------------------------------------------------
// File: A2SimpleDriver.java // Author: (your name here) / Rita Ester // Date: September 23, 2017 // Description: Basic test driver for CSCI 225 assignment #2 // This file tests some functions of the DLinkedList class of assignment #2. // Not all special cases have been tested; you will be responsible for adding // your own test code and function calls to this file in order to thoroughly // test all general and boundary cases for your functions. // In general, please ensure that you test: // 1. invalid parameter(s) // 2. valid parameter(s), boundary case // 3. valid parameter(s), general case
import java.util.ArrayList;
public class A2SimpleDriver { public static void main(String[] args) { System.out.println("Entering DLinkedList test method..."); listTest_0917(); System.out.println("DLinkedList test method complete!!!");
}
public static void listTest_0917() { DLinkedList ------------------------------------------------------------------------------------------------------------------ // File: DLinkedList.java // Author: (your name here) // Geoffrey Tien/ Rita Ester // Date: September 23, 2017 // Description: Implementation of a generic doubly-linked list class // and list node import java.util.ArrayList; public class DLinkedList { private class DListNode { public IT data; public DListNode public DListNode public DListNode(IT value) { data = value; prev = null; next = null; } } private DListNode private DListNode private int size; // public methods // default constructor public DLinkedList(){ // to be completed } // copy constructor, clones the sourceList public DLinkedList(DLinkedList // to be completed } // Inserts an item at the front of the list // POST: List contains item at position 0 // PARAM: item = item to be inserted public void insertFront(T item){ // to be completed } // Inserts an item at the back of the list // Special case: The empty list // POST: List contains item at back // PARAM: item = item to be inserted public void insertBack(T item){ // to be completed } // Inserts an item in position p (0-indexed). // Throws exception for invalid index (IndexOutOfBoundsException). // PRE: 0 // POST: List contains item at position p // PARAM: item = item to be inserted, p = position where item will be inserted public void insertAt(T item, int p){ // to be completed } // Removes and returns an item from position p (0-indexed). // Throws exception if list is empty (IllegalStateException) or // if index is invalid (IndexOutOfBoundsException). // PRE: 0 // POST: Item is removed from list, size has been decreased by 1. // PARAM: p = position from where item will be removed. public T removeAt(int p){ // to be completed } // Removes duplicates from the list, preserving existing order of remaining items. // The first occurrence of any duplicate (relative to the front of the list) // is the one which remains. // This method should be implemented to have O(n^2) running time or better // PRE: // POST: List contains no duplicates, front and back point to the appropriate nodes // PARAM: public void removeDuplicates(){ // to be completed // use two node references // ptrA iterates from front to back // ptrB iterates from ptrA to back // use the equals method to compare two data elements of type DListNode DListNode } // empties the list public void clear(){ // to be completed } // ACCESSORS // returns the size of the list public int size(){ // to be completed } // returns whether the list is empty public boolean isEmpty(){ // to be completed } // returns existence of item public boolean contains(T item){ // to be completed // use the equals method to compare two data items of type } // Returns item at index p (0-indexed) // Throws exception for invalid index (IndexOutOfBoundsException) public T elementAt(int p) { if (p = size) throw new IndexOutOfBoundsException("DLinkedList::elementAt - invalid position"); else{ // to be completed } } // For testing purposes // inserts list contents to an ArrayList, traverses from front to back public ArrayList { ArrayList DListNode int count = 0; while (nd != null && count { al.add(nd.data); nd = nd.next; count++; } return al; } // For testing purposes // inserts list contents to an ArrayList, traverses from back to front public ArrayList { ArrayList DListNode int count = 0; while (nd != null && count { al.add(nd.data); nd = nd.prev; count++; } return al; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
