Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions