I need help with implementing grow and shrink Here is the actually instructions--->
•grow(). This method, when called, will “grow” arrayStack by utilizing the strategy outlined in 2 above. This method will only be called by push(). Note that grow() should be private.
•shrink(). This method, when called, will shrink arrayStack by utilizing a strategy similar to that outline in 2 above. This method will only be called by pop() and will only be executed when the “occupied” part of the array is less than or equal to half the size of arrayStack. Note that after a call to shrink, the size of arrayStack should be equal to the number of “occupied” slots. Note also that shrink() should be private.
this is what I have done so far---> I have couple errors and I not sure what I am doing wrong..
public class ArrayStack {
private int[] arrayStack = new int[50];
private int index = -1;
public ArrayStack() {}
public boolean isEmpty() {
return index == -1;
}
public void push(int num) {
arrayStack[++index] = num;
}
public Boolean isFull() {
if( isFull()) {
return index =arrayStack.length – 1;
}
else
public void push(int num) {
if (isFull()) {
throw new FullStackException("Trying to push onto a full stack!");
}
arrayStack[++index] = num;
}
private int grow (int num) {
arrayStack++;
}
public int shrink(int num) {
arrayStack--;
public int pop() {
if (isEmpty()) {
throw new EmptyStackException("Trying to pop from an empty stack!");
}
return arrayStack[index--];
}
public void printStack() {
for (int i = 0; i < arrayStack.length; i++) {
System.out.println(arrayStack[i]);
}
}
}