Question: Write a class StackReverse that supports the following operations, with running time O(1) for each operation. public class StackReverse { public StackReverse() - a constructor,

Write a class StackReverse that supports the following operations, with running time O(1) for each operation.

public class StackReverse {

public StackReverse() - a constructor, creates an empty stack public

void push(T item) - adds an element to the stack public

T pop() - removes an element from the stack public

void reverse() - reverses the order of the elements. That is, the element that was the last in the stack becomes the first, and vice versa

public int size() - returns the number of elements in the stack

public boolean isEmpty() - checks if the stack is empty } The running time of each operation must be O(1).

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!