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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started