Question: Write java code to build a Stack using a NodePositionList as the underlying data structure. You should assume the NodePositionList has the PositionList interface as

Write java code to build a Stack using a NodePositionList as the underlying data structure. You should assume the NodePositionList has the PositionList interface as shown on pg. 275; i.e., use the methods shown on those pages. You should use the adapter pattern discussed in class. Your class (NodeListStack) should merely call the NodeList methods. It must be able to satisfy the exception behavior specified by the Stack ADT.

Write java code to build a Stack using a NodePositionList as the

/** An interface for positional lists. */ public interface PositionalList { /** Returns the number of elements in the list. */ int size();

/** Tests whether the list is empty. */ boolean isEmpty();

/** Returns the first Position in the list (or null, if empty). */ Position first();

/** Returns the last Position in the list (or null, if empty). */ Position last();

/** Returns the Position immediately before Position p (or null, if p is first). */ Position before(Position p) throws IllegalArgumentException;

/** Returns the Position immediately after Position p (or null, if p is last). */ Position after(Position p) throws IllegalArgumentException; /** Inserts element e at the front of the list and returns its new Position. */ Position addFirst(E e);

/** Inserts element e at the back of the list and returns its new Position. */ Position addLast(E e);

/** Inserts element e immediately before Position p and returns its new Position. */ Position addBefore(Position p, E e) throws IllegalArgumentException;

/** Inserts element e immediately after Position p and returns its new Position. */ Position addAfter(Position p, E e) throws IllegalArgumentException;

/** Replaces the element stored at Position p and returns the replaced element. */ E set(Position p, E e) throws IllegalArgumentException;

/** Removes the element stored at Position p and returns it (invalidating p). */ E remove(Position p) throws IllegalArgumentException;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!