Question: JAVA: Suppose we define an IntArrayStack class that implements the interface Stack . (See exercise 307.) Our class has instance variables private Integer [] theArray;

JAVA:

Suppose we define an IntArrayStack class that implements the interface Stack. (See exercise 307.) Our class has instance variables

private Integer [] theArray; // To hold the values in the stack private int topIndex; // For an empty stack, topIndex = -1 public final int maxSize; // the size of theArray after it gets allocated

Implement the push method . (You should be able to figure out what the method header looks like.)

In the case of a full stack, throw RuntimeException with the message "Stack is full."

Otherwise increment topIndex and assign the method 's parameter to theArray at the new topIndex.

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!