Question: Java Create a class called Inverse_Stack where stack is organized in such a way where the first bottom element is located at index ( -

Java

Create a class called Inverse_Stack where

stack is organized in such a way where the first

bottom element is located at index ( - 1).

This class MUST

implement

the StackADT interface

Reuse & modify the 'ArrayStack' class (since its generics and

attributes are already established and are [still] important to have)

Must not be derived from ArrayStack

Each element pushed is placed into the array slot that before the

[current] top-most element

IE. If (size = 0), store at index: (length - 1);

If (size = 1), store at index: (length - 2);

If (size = 2), store at index: (length - 3);

etc.

Important

: You must implement a version of "

expandCapacity that Keep track of TWO [separate] indices

All attributes and the expandCapacity method should beprivate DON'T need to create a " toString "method, though you can if desired

Your class must have TWO constructors: a default constructor and

another constructor with a single integer parameter

You can even reuse / modify the ones from class 'ArrayStack', so

long as they work out as intended for this particular assignment

(given how our inverse stack is suppose to behave)

public interface StackADT

{

public void push(T element);

public T pop();

public T peek();

public boolean isEmpty();

public int size();

}

public class ArrayStack implements StackADT

{

private T[] stack;

public ArrayStack{ }

{

this(100);

}

public ArrayStack(int capacity)

{

stack = (T[]) new Object[capacity];

}

Define StackADT's methods here.

}

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!