Question
java program For this question, you must implement the class (static) method boolean isSkipped(Stack s1, Stack s2). The method isSkipped returns true if and only
java program
For this question, you must implement the class (static) method boolean isSkipped(Stack s1, Stack s2).
The method isSkipped returns true if and only if the stacks designated by s1 and s2 contain the same elements, in the same order, but with elements 2,4,6,. . . missing in s2. Given s1 designating a stack containing the elements 1,2,3,4,5,6,7, where 7 is the top element, and s2 designating a stack containing the elements 1,3,5,7, where 7 is the top element, isSkipped(s1, s2) returns true.
Both stacks, designated by s1 and s2, must remain unchanged following a call to the method isSkipped. Specifically, given s1 and s2, two reference variables designating stacks, following the call isSkipped(s1, s2), s1 contains the same elements, in the same order, as it did before the call to isSkipped. Similarly, s2 contains the same elements, in the same order, as it did before the call to isSkipped
You can assume that both, s1 and s2, will not be null.
An empty stack is considered the skipped version of another empty stack.
The parameters of the method isSkipped are of type Stack, which is an interface.
For this question, there is an interface named Stack:
Notice that the parameter of the method push and the return value of the method pop are of type int.
Assume the existence of DynamicStack, which implements the interface Stack. It has one constructor and its signature is DynamicStack().
You cannot use arrays to store temporary data.
You must use objects of the class DynamicStack() to store temporary data
You do not know anything about the implementation of DynamicStack. In particular, you do not know if it uses an array or not.
You can assume that DynamicStack can store an arbitrarily large number of elements.
public interface Stack public abstract void push (int item); public abstract int pop public abstract boolean isEmptyStep 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