Using Java, write a MyStack class that implements the StackInterface using a linked list. Your MyStack class is required to use a private inner class implementation for the node of the linked list called Node. In addition to implementing the methods defined in StackInterface, your MyStack class must override the toString method defined in the Object class. toString should return the String representation of the current state of MyStack. For example, if we created a new MyStack object and pushed 256, 1, 9, 20, and 2018 onto the stack, the toString method should return: TOP: 2018 | 20 | 9 | 1 | 256 |
An interface for the ADT stack @author Frank M. Carrano @author Timothy M. Henry @version 4.0 public interface StackIntertace
Adds a new entry to the top of this stack @param newEntryAn object to be added to the stack. */ public void push(T newEntry); Removes and returns this stack's top entry. @returnThe object at the top of the stack. @throws if the stack is empty before the operation. */ public T pop(); /**Retrieves this stack's top entry @returnThe object at the top of the stack. @throwsEmptyStackExceptign if the stack is empty. */ public T peek(); /**Detects whether this stack is empty. public boolean isEmpty(); @ret if the stack is empty. */ Removes all entries from this stack. */ public void clear(); } // end StackInterface