Question: Suppose we were going to modify the BoundedArrayStack to be an UnboundedArrayStack that doubles the size of the backing array instead of throwing a StackOverflowException.

Suppose we were going to modify the BoundedArrayStack to be an UnboundedArrayStack that doubles the size of the backing array instead of throwing a StackOverflowException.

(3 points) Update the method(s) of BoundedArrayStack required to make it into an UnboundedArrayStack; show the full signature and body of any method(s) you modify or add. Be sure your new method(s) still implement the interface!

package stack; public interface Stack { void push(E e) throws StackOverflowException; E pop() throws StackUnderflowException; E peek() throws StackUnderflowException; boolean isEmpty(); boolean isFull(); int size(); } 
////// package stack; public class BoundedArrayStack implements Stack { private E[] array; private int top; public BoundedArrayStack(int capacity) { array = (E[]) new Object[capacity]; top = -1; } @Override public void push(E e) throws StackOverflowException { if (isFull()) { throw new StackOverflowException(); } top++; array[top] = e; } @Override public E pop() throws StackUnderflowException { if (isEmpty()) { throw new StackUnderflowException(); } E item = array[top]; array[top] = null; top--; return item; } @Override public E peek() throws StackUnderflowException { if (isEmpty()) { throw new StackUnderflowException(); } return array[top]; } @Override public boolean isEmpty() { return top == -1; } @Override public boolean isFull() { return top == array.length - 1; } @Override public int size() { return top + 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!