I have already done number 1. I just need help with number 2. Implement Stack with an internal LineNodePlus. You have been given the code for the StackADT interface and all of the List files needed. You must come up with a new Stack.java that implements the StackADT interface and uses a LineNodesPlus internally to store the stack. Construct test cases for the Stack (StackTest.java) to ensure it works correctly. StackADT.java public interface StackADT { // Stack class ADT /** * Clears the stack. */ public void clear(); /** * Pushes argument it onto the stack. Argument is stored in the top of the * stack. Returns false if the stack is out of space. * * @param it value to be pushed onto the stack * @return true if the value is stored */ public boolean push(E it); /** * Pop and return the value at the top of the stack. * * @return value stored at the top of the stack */ public E pop(); /** * Returns the value at the top of the stack. It does not modify the stack. * * @return value stored at the top of the stack */ public E topValue(); /** * Returns the number of elements stored in the stack. * * @return the number of elements in the stack. */ public int numElements(); /** * Returns true if the stack is empty, false otherwise. * * @return true if the stack is empty. */ public boolean isEmpty(); } Stack.java public class Stack implements StackADT { ListNodePlus stack; }
I have already done number 1. I just need help with number 2.
- Implement Stack<E> with an internal LineNodePlus<E>. You have been given the code for the StackADT<E> interface and all of the List files needed. You must come up with a new Stack.java that implements the StackADT interface and uses a LineNodesPlus internally to store the stack.
-
Construct test cases for the Stack (StackTest.java) to ensure it works correctly.
StackADT.java
public interface StackADT<E>
{ // Stack class ADT
/**
* Clears the stack.
*/
public void clear();
/**
* Pushes argument it onto the stack. Argument is stored in the top of the
* stack. Returns false if the stack is out of space.
*
* @param it value to be pushed onto the stack
* @return true if the value is stored
*/
public boolean push(E it);
/**
* Pop and return the value at the top of the stack.
*
* @return value stored at the top of the stack
*/
public E pop();
/**
* Returns the value at the top of the stack. It does not modify the stack.
*
* @return value stored at the top of the stack
*/
public E topValue();
/**
* Returns the number of elements stored in the stack.
*
* @return the number of elements in the stack.
*/
public int numElements();
/**
* Returns true if the stack is empty, false otherwise.
*
* @return true if the stack is empty.
*/
public boolean isEmpty();
}
Stack.java
public class Stack<E> implements StackADT<E>
{
ListNodePlus<E> stack;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps