Redesign the ArrayStack implementation on page 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 default array capacity
private E data; generic array used for storage
private int ; index of the top element in stack
public ArrayStack thisCAPACITY; constructs stack with default capacity
public ArrayStackint capacity constructs stack with given capacity
data new Objectcapacity; safe cast; compiler may give warning
public int size return ;
public boolean isEmpty return
public void push e throws IllegalStateException
if size data. length throw new IllegalStateExceptionStack is full";
data; increment before storing new item
public top
if isEmpty return null;
return datat;
public pop
if isEmpty return null;
answer data;
data null; dereference to help garbage collection
;
return answer;