Question: Complete the global method duplicateElement in the class xxx which receives a stack and a number and returns a new stack that contains a
Complete the global method " duplicateElement" in the class "xxx" which receives a stack and a number and returns a new stack that contains a copy of the received stack but the elements that are equal to the received number are duplicated.
Note that:
- You are not allowed to modify or print anything, just complete the implementation of the method.
- You have to keep the order of new stack the same as the original stack.
Example:
Original stack: S = [1, 2, 3, 4, 5] After calling the method with S and 3: New stack = [1, 2, 3, 3, 4, 5]
public class xxx {
static public stack duplicatrElement(Stack originalStaxl, int num){
// note that;
// you are not allowed to modify or print
// jast complete the implemention
// you have to keep the order of new stack the same as the original stack
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
