Question: Redesign the ArrayStack implementation on page 2 3 0 of the recommended textbook ( Data Structures and Algorithms, Six edition ) to double the array

Redesign the ArrayStack implementation on page 230 of the recommended textbook (Data Structures and Algorithms, Six edition)
to double the array size when it reaches maximum capacity for push operation.
public class ArrayStack implements Stack
public static final int CAPACITY =1000;?? default array capacity
private E[] data; ,?? generic array used for storage
private int t=-1;,?? index of the top element in stack
public ArrayStack(){ this(CAPACITY); }/// constructs stack with default capacity
public ArrayStack(int capacity){// constructs stack with given capacity
data =(E[]) new Object[capacity]; ,?? safe cast; compiler may give warning
}
public int size(){ return (t+1);
public boolean isEmpty(){ return (t==-1
public void push(E e) throws IllegalStateException {
if ( size()== data. length) throw new IllegalStateException("Stack is full");
data[++t]=e;,?? increment t before storing new item
}
public E top(){
if (isEmpty()) return null;
return data[t];
}
public E pop(){
if (isEmpty()) return null;
E answer =data[t];
data [t]= null; ,?? dereference to help garbage collection
t--;
return answer;
}
}
 Redesign the ArrayStack implementation on page 230 of the recommended textbook

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To redesign the ArrayStack implementation so that the array size doubles when it reaches maximum cap... View full answer

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!