Question: Receive these two errors: Any ideas on how to solve this? In this lab, you will modify your array implementation of the stack. Again, the

 Receive these two errors: Any ideas on how to solve this?In this lab, you will modify your array implementation of the stack.Again, the UndoRedo program will be used to test the implementation. Yourtask is to modify ArrayStack.java so that topOfStackIndex is initialized to data.length-1.This will mean that the stack will grow from the end of

Receive these two errors:

the array (index length-1) to the beginning (index 0.) Note that the

Any ideas on how to solve this?

In this lab, you will modify your array implementation of the stack. Again, the UndoRedo program will be used to test the implementation. Your task is to modify ArrayStack.java so that topOfStackIndex is initialized to data.length-1. This will mean that the stack will grow from the end of the array (index length-1) to the beginning (index 0.) Note that the UndoRedo application will be unaware of the change in the stack implementation. 291754.1618358.qx3zay 7 import java.util.*; public class ArrayStack implements Stack { public static final int DEFAULT_STACK_SIZE = 10; private int topOfStackIndex; // index of the next empty spot on the stack private object[] data; // the stack private int growthIncrement; // the number of elements to increase the array when it is full public ArrayStack(int size, int growthIncrement) { /* In this constructor: a) Create the array that will represent the stack. b) Initialize the instance variable, topOfStackIndex. c) Invoke the setter to initialize instance variable, growth Increment, with the appropriate formal parameter. this.data = new Object[size]; for(int i = 0; i 0) { this.growth Increment = growthIncrement; } } public void push(object element) { if (topOfStackIndex == data. length -1) growStack(); data[topOfStackIndex] = element; topOfStackIndex++; } public Object peek) throws EmptycollectionException { if (isEmpty) throw new EmptycollectionException("ArrayStack"); else return data[topOfStackIndex-1]; } public Object pop() throws EmptycollectionException { Object result = peek(); topOfStackIndex--; data[topOfStackIndex] = null; return result; } public boolean isEmpty() { return size) 0; } public int size() { Returns the number of items on the stack. int count = 0; for(int i = 0; i

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!