Question
1. Implement the methods specified for the unbounded stack (LinkedStack) * Add an inspector method inspect(int n) . The method will return the nth element
1. Implement the methods specified for the unbounded stack (LinkedStack)
* Add an inspector method inspect(int n). The method will return the nth element in the stack. By traversing the linked list to find that element (NOT USING LLNode
* Implement the method popSome(int count). The method will remove the top count items from the stack. The method should throw a StackUnderFlow Exception as needed. Note that you may have some room for decisions in this method, but possible less choices than with the Array implementation. Document approach in the comments.
* Without adding any new instance variables, implement a size() method. The method will return an integer value indicating the number of elements in the stack. You will need to traverse your stack nodes using a while loop.
** These methods will not be part of the StackInterface or the BoundedStackInterface. You dont need to define them in the interface declarations.
2. Test code in the LinkedStackTester to show the results of using the new methods
public class LLNode
private T data; private LLNode
----------------------------------------------------------------------------------------
import Support.LLNode;
public class LinkedStack
private LLNode
}
@Override public T peek() throws StackUnderflowException { // TODO Auto-generated method stub return null; }
@Override public boolean isEmpty() { // TODO Auto-generated method stub return (top == null); }
@Override public int size() { // TODO Auto-generated method stub return 0; }
@Override public void push(T data) { // TODO Auto-generated method stub LLNode
----------------------------------------------------------------------------------------
public interface StackInterface
----------------------------------------------------------------------------------------
public interface UnboundedStackInterface
void push(T element); }
----------------------------------------------------------------------------------------
public class StackOverflowException extends RuntimeException { public StackOverflowException() { super(); } public StackOverflowException(String message) { super(message); } }
----------------------------------------------------------------------------------------
public class StackUnderflowException extends RuntimeException { public StackUnderflowException() { super(); } public StackUnderflowException(String message) { super(message); } }
----------------------------------------------------------------------------------------
public class LinkedStackTester {
public static void main(String[] args) { LinkedStack
} }
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