Question: 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

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!