Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the ADT stack (named Stack274) using an array to stores the entries. This class must implement the textbooks StackInterface. Expand the array dynamically by

Implement the ADT stack (named Stack274) using an array to stores the entries. This class must implement the textbooks StackInterface. Expand the array dynamically by 2X (i.e., a resizable array) when a push is called and the array is full.Also, reduce the size of the array (cut the array size in half) when a pop results in less than 25% of the array being used; the size of the array should always be at least 20. Maintain the stacks bottom entry in stack[stack.length-1].

public interface StackInterface {

/**

* Adds a new entry to the top of this stack.

*

* @param newEntry An object to be added to the stack.

*/

public void push(T newEntry);

/**

* Removes and returns this stack's top entry.

*

* @return The object at the top of the stack.

* @throws EmptyStackException if the stack is empty before the operation.

*/

public T pop();

/**

* Retrieves this stack's top entry.

*

* @return The object at the top of the stack.

* @throws EmptyStackException if the stack is empty.

*/

public T peek();

/**

* Detects whether this stack is empty.

*

* @return True if the stack is empty.

*/

public boolean isEmpty();

/** Removes all entries from this stack. */

public void clear();

public int size();

} // end StackInterface

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions