Question
Modify the single linked list java code to implement a DOUBLY linked list. [Data Structures] PLEASE SEE THIS LINK FOR ALL OF THE JAVA FILES
Modify the single linked list java code to implement a DOUBLY linked list. [Data Structures]
PLEASE SEE THIS LINK FOR ALL OF THE JAVA FILES INCLUDING NODE.JAVA https://pastebin.com/t6Xfix8h
*** CODE TO BE MODIFIED ***
ListReferenceListBased.java
/** * Reference-based implementation of ADT list. * Modify the code to implement a doubly linked list. * @author */
import java.util.Iterator;
public class ListReferenceBased implements ListInterface, Iterable{
/** reference to the first element of the list */ private Node head; /** number of items in list */ private int numItems; /** default constructor */ public ListReferenceBased() { numItems = 0; head = null; } // end default constructor /** Tests if this list has no elements. * @return true if this list has no elements; * false otherwise. */
public boolean isEmpty() { return numItems == 0; } // end isEmpty /** * Returns the number of elements in this list. * @return the number of elements in this list. */
public int size() { return numItems; } // end size
/** Locates a specified node in a linked list. *
- Postcondition: * @param index position of the desired node. Assumes that * 1
/** get the item location at the specified position in the list * @param index position of the node containing the item * @return the Object located at the specified index * @throws ListIndexOutOfBoundsException if the index is out of * range, i.e. when index size() */ public E get(int index) throws ListIndexOutOfBoundsException { if (index >= 1 && index size()). */ public void add(int index, E item) throws ListIndexOutOfBoundsException { if (index >= 1 && index
/** * appends the specified element to the end of this list. * @param elt element to be added at the end of the list */ public void append(E item) { // TO COMPLETE }//end append
/** * Removes the element at the specified position in this * list. Shifts any subsequent elements to the left (subtracts one * from their indices). * @param index the index of the element to remove * @throws IndexOutOfBoundsException - if index is out of range * (index size()). */ public void remove(int index) throws ListIndexOutOfBoundsException { if (index >= 1 && index
/** * delete the the specified element in this list if exists, * otherwise state that the item is not in the current * list. Shifts any subsequent elements to the left (subtracts one * from their indices). * @param elt the element, if it exists, to delete */ public void delete(E item){ //TO COMPLETE } /** * Looks for the index of the specified element in this list. If * the element is not present, the method returns -1 * @param elt the element which index is looked for. * @return either the index of the location in the list where the * argument is present or -1 if the argument is not * contained in the list. */ public int contains(E elt){ // TO COMPLETE } /** * Prints all the elements in this list on the console in sequence */ public void display(){ // TO COMPLETE }
/** * Prints all the elements in this list on the console in reverse * order */ public void displayReverse(){ // TO COMPLETE }
public ListReferenceBasedIterator iterator(){ return new ListReferenceBasedIterator(head); } public class ListReferenceBasedIterator implements Iterator{ Node current;
public ListReferenceBasedIterator(Node node){ current=node; } public boolean hasNext(){ return (current!=null); }
public E next(){ E elt = current.getItem(); current = current.getNext(); return elt; }
public void remove(){} } } // end ListReferenceBased
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started