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:

  1. You are not allowed to modify or print anything, just complete the implementation of the method.
  2. 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

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!