Question: Modify the Stack ADT implementations Utilizing your Stack ADT implementations: Implement the methods specified for the bounded stack (ArrayStack) Add an inspector method inspector(int loc).

Modify the Stack ADT implementations Utilizing your Stack ADT implementations: Implement the methods specified for the bounded stack (ArrayStack) Add an inspector method inspector(int loc). The method will return the element found at the location loc. Return null if the location is invalid. Implement 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 will have some room for decisions in this method. Document your 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. ** These methods will not be part of the StackInterface or the BoundedStackInterface. You dont need to define them in the interface declarations.

package ch03; public class ArrayStack implements BoundedStackInterface { protected int DEFCAP = 100; protected T[] stack; protected int topIndex; public ArrayStack() { topIndex = -1; stack = (T[]) new Object[DEFCAP]; } public ArrayStack(int capacity) { topIndex = -1; stack = (T[]) new Object[capacity]; } @Override public void pop() throws StackUnderflowException { // TODO Auto-generated method stub if (isEmpty()) { throw new StackUnderflowException("Stack is empty"); } else { topIndex--; } } @Override public T top() throws StackUnderflowException { // TODO Auto-generated method stub if (isEmpty()) { throw new StackUnderflowException("Stack is empty"); } else { return stack[topIndex]; } } @Override public boolean isEmpty() { // TODO Auto-generated method stub return (topIndex == -1); } @Override public void push(T element) throws StackOverflowException { // TODO Auto-generated method stub if (isFull()) { throw new StackOverflowException("Stack is full"); } else { topIndex++; stack[topIndex] = element; } } @Override public boolean isFull() { // TODO Auto-generated method stub return (topIndex == stack.length-1); } }

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!