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

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!