Question
Implement the following code: For the class StackInspector on the next page, complete the implementation of the method findLast(E elem). The method findLast returns the
Implement the following code:
For the class StackInspector on the next page, complete the implementation of the method findLast(E elem).
The method findLast returns the index of the last occurrence of the specified element in the stack. If there is more than one occurrence, the last occurrence is the one closest to the bottom of the stack. This is also the one with the highest index.
The method returns -1 if the stack does not contain the element.
The value of the index increases from top to bottom. The index of the top element is 0.
The method findLast does not change the state of the stack. That is before and after a call to the method, the stack must contain the same elements, in the same order. The value null is not a valid value for the parameter elem
public interface Stack
boolean isEmpty();
E peek();
E pop();
void push(E element);
}
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