Question: **Java code** ** Add Entry class to test** public class FavoriteList { protected PositionList fList; // List of entries /** Constructor; O(1) time */ public
**Java code** ** Add Entry class to test**
public class FavoriteList
//Complete your work and write out a main function to test. // Top, access and remove methods.
****** Please who can help with this question in Java programming language
This is the implementation of the NodePositionList & PositionList class
******NodePositionList
import java.util.Iterator;
public class NodePositionList
protected int numElts; // Number of elements in the list protected DNode
/** * Constructor that creates an empty list; O(1) time */ public NodePositionList() { numElts = 0; header = new DNode
/** * Returns the number of elements in the list; O(1) time */ public int size() { return numElts; }
/** * Returns whether the list is empty; O(1) time */ public boolean isEmpty() { return (numElts == 0); }
/** * Returns the first position in the list; O(1) time */ public Position
return header.getNext(); }
/** * Returns the first position in the list; O(1) time */ public Position
return trailer.getPrev(); }
/** * Returns the position before the given one; O(1) time */ public Position
return prev; }
/** * Returns the position after the given one; O(1) time */ public Position
return next; }
/** * Insert the given element before the given position, returning * the new position; O(1) time */ public void addBefore(Position
/** * Insert the given element after the given position, returning * the new position; O(1) time */ public void addAfter(Position
/** * Insert the given element at the beginning of the list, returning * the new position; O(1) time */ public void addFirst(E element) { numElts++; DNode
/** * Insert the given element at the beginning of the list, returning * the new position; O(1) time */ public void addLast(E element) { numElts++; DNode
/** * Remove the given position from the list; O(1) time */ public E remove(Position
return vElem; }
/** * Replace the element at the given position with the new element * and return the old element; O(1) time */ public E set(Position
return oldElt; }
/** * Returns a textual representation of a given node list */ public static
return s + "]"; }
/** Returns an iterator of all the elements in the list. */ public Iterator
/** * Returns an iterable collection of all the nodes in the list. */ public Iterable
class EmptyListException extends RuntimeException { public EmptyListException(String err) { super(err); } }
***********PositionList
/** * An interface for a position list. */
public interface PositionList
/** * Returns the number of elements in this list. */ public int size();
/** * Returns whether the list is empty. */ public boolean isEmpty();
/** * Returns the first node in the list. */ public Position
/** * Returns the last node in the list. */ public Position
/** * Returns the node after a given node in the list. */ public Position
/** * Returns the node before a given node in the list. */ public Position
/** * Inserts an element at the front of the list, returning new position. */ public void addFirst(E e);
/** * Inserts and element at the back of the list, returning new position. */ public void addLast(E e);
/** * Inserts an element after the given node in the list. */ public void addAfter(Position
/** * Inserts an element before the given node in the list. */ public void addBefore(Position
/** * Removes a node from the list, returning the element stored there. */ public E remove(Position
/** * Replaces the element stored at the given node, returning old element. */ public E set(Position
/** * Returns an iterable collection of all the nodes in the list. */ public Iterable
}
class InvalidPositionException extends RuntimeException { public InvalidPositionException(String err) { super(err); } }
class BoundaryViolationException extends RuntimeException { public BoundaryViolationException(String err) { super(err); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
